Skip to content

Add data for method POST #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ endpoints:
- CREATE_INCIDENT
public_incidents: true
frequency: 5
- name: POST-API
url: http://www.example.com/api/login
method: POST
header:
Content-Type: application/json
data: '{ "username": "ping", "password": "pong"}'
timeout: 1 # seconds
expectation:
- type: HTTP_STATUS
status_range: 200-205
incident: MAJOR
- type: LATENCY
threshold: 1
- type: REGEX
regex: ".*token.*"
threshold: 10
allowed_fails: 0
component_id: 2
action:
- CREATE_INCIDENT
public_incidents: true
latency_unit: ms
frequency: 5
cachet:
api_url: http://status.cachethq.io/api/v1
token:
Expand Down
6 changes: 4 additions & 2 deletions cachet_url_monitor/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Configuration(object):
endpoint_url: str
endpoint_timeout: int
endpoint_header: Dict[str, str]
endpoint_data: str

allowed_fails: int
component_id: int
Expand Down Expand Up @@ -91,6 +92,7 @@ def __init__(self, config, endpoint_index: int, client: CachetClient, webhooks:
self.endpoint_timeout = self.endpoint.get("timeout") or 1
self.endpoint_header = self.endpoint.get("header") or None
self.allowed_fails = self.endpoint.get("allowed_fails") or 0
self.endpoint_data = self.endpoint.get("data") or None

self.component_id = self.endpoint["component_id"]
self.metric_id = self.endpoint.get("metric_id")
Expand Down Expand Up @@ -158,11 +160,11 @@ def evaluate(self):
"""
try:
if self.endpoint_header is None:
self.request = requests.request(self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout)
self.request = requests.request(self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout, data=self.endpoint_data)
else:
self.request = requests.request(
self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout, headers=self.endpoint_header,
verify=not self.endpoint['insecure'] if 'insecure' in self.endpoint else True
verify=not self.endpoint['insecure'] if 'insecure' in self.endpoint else True, data=self.endpoint_data
)

self.current_timestamp = int(time.time())
Expand Down