Includes: - 3 Python actions (hello, http_example, read_counter) - 1 counter trigger type - 1 counter sensor (Python, keystore-backed, per-rule state) - 1 example rule (count_and_log) - requirements.txt with requests and pika - README with full usage documentation
23 lines
616 B
Python
23 lines
616 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
HTTP Example Action - Python Example Pack
|
|
|
|
Demonstrates using the `requests` library to make an HTTP call to example.com.
|
|
Receives parameters via stdin JSON (through the Python wrapper).
|
|
"""
|
|
|
|
import requests
|
|
|
|
|
|
def run(url="https://example.com", **kwargs):
|
|
"""Fetch a URL and return status and a snippet of the response body."""
|
|
response = requests.get(url, timeout=10)
|
|
|
|
return {
|
|
"status_code": response.status_code,
|
|
"url": response.url,
|
|
"content_length": len(response.text),
|
|
"snippet": response.text[:500],
|
|
"success": response.ok,
|
|
}
|