Browse Source

Additional python usage examples

pull/211/head
Pēteris Caune 6 years ago
parent
commit
d36d4fb543
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 25 additions and 1 deletions
  1. +1
    -1
      CHANGELOG.md
  2. +1
    -0
      hc/front/management/commands/pygmentize.py
  3. +8
    -0
      templates/front/docs.html
  4. +8
    -0
      templates/front/snippets/python_requests_payload.html
  5. +7
    -0
      templates/front/snippets/python_requests_payload.txt

+ 1
- 1
CHANGELOG.md View File

@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
### Improvements ### Improvements
- Set Pushover alert priorities for "down" and "up" events separately - Set Pushover alert priorities for "down" and "up" events separately
- Additional python usage examples
### Bug Fixes ### Bug Fixes
- Fix after-login redirects (the "?next=" query parameter) - Fix after-login redirects (the "?next=" query parameter)


+ 1
- 0
hc/front/management/commands/pygmentize.py View File

@ -36,6 +36,7 @@ class Command(BaseCommand):
_process("python_urllib2", lexers.PythonLexer()) _process("python_urllib2", lexers.PythonLexer())
_process("python_requests", lexers.PythonLexer()) _process("python_requests", lexers.PythonLexer())
_process("python_requests_fail", lexers.PythonLexer()) _process("python_requests_fail", lexers.PythonLexer())
_process("python_requests_payload", lexers.PythonLexer())
_process("php", lexers.PhpLexer()) _process("php", lexers.PhpLexer())
_process("powershell", lexers.shell.PowerShellLexer()) _process("powershell", lexers.shell.PowerShellLexer())
_process("powershell_inline", lexers.shell.BashLexer()) _process("powershell_inline", lexers.shell.BashLexer())


+ 8
- 0
templates/front/docs.html View File

@ -174,6 +174,14 @@ thing: they fire off a HTTP GET method.</p>
{% include "front/snippets/python_urllib2.html" %} {% include "front/snippets/python_urllib2.html" %}
<p>
You can include additional diagnostic information in the
in the request body (for POST requests), or in the "User-Agent"
request header:
</p>
{% include "front/snippets/python_requests_payload.html" %}
<a name="ruby"></a> <a name="ruby"></a>
<h3 class="docs-example">Ruby</h3> <h3 class="docs-example">Ruby</h3>
{% include "front/snippets/ruby.html" %} {% include "front/snippets/ruby.html" %}


+ 8
- 0
templates/front/snippets/python_requests_payload.html View File

@ -0,0 +1,8 @@
<div class="highlight"><pre><span></span><span class="c1"># Passing diagnostic information in the POST body:</span>
<span class="kn">import</span> <span class="nn">requests</span>
<span class="n">requests</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">&quot;{{ ping_url }}&quot;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="s2">&quot;temperature=-7&quot;</span><span class="p">)</span>
<span class="c1"># Passing diagnostic information in the User-Agent header:</span>
<span class="kn">import</span> <span class="nn">requests</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;{{ ping_url }}&quot;</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;User-Agent&quot;</span><span class="p">:</span> <span class="s2">&quot;temperature=-7&quot;</span><span class="p">})</span>
</pre></div>

+ 7
- 0
templates/front/snippets/python_requests_payload.txt View File

@ -0,0 +1,7 @@
# Passing diagnostic information in the POST body:
import requests
requests.post("PING_URL", data="temperature=-7")
# Passing diagnostic information in the User-Agent header:
import requests
requests.get("PING_URL", headers={"User-Agent": "temperature=-7"})

Loading…
Cancel
Save