We use the
Redmine project and task management system. Zabbix and other monitoring systems are tied to it. And here's how the idea came to integrate it with StatusCake for the convenience of monitoring all tasks in one system.
There is such a system of online monitoring
StatusCake . It allows you to build quite complex checks for sites, checks their availability, access speed, builds various beautiful graphics.
But we are not interested in this functionality, like any monitoring system it has a mechanism for reporting problems. Ways of notification are quite varied. There is integration with different services, in particular with twitter (why should it be published when the server crashes). But there is no integration with Redmine. But there is an opportunity to use webhook. What we have used. Below under the cut that we did.
To begin with, on one of the servers where we located the monitoring system was located a simple php script that was called every time the server status changed in StatusCake. This script is passed json, which in general contains:
<code> [URL] => [Token] => [Name] => [StatusCode] => [Status] => </code>
- The URL is the url for which the check takes place.
- Token is a hash of the username and key API, used for verification.
- Name is the name of the test in statuscake which has changed its state.
- StatusCode - the code that returned the site when accessing the specified URL.
- Status is the status of the host, it can be 'UP' and 'DOWN'.
')
The script performs only two functions, receives data and calls a python script, to which it transfers the received values. The script itself:
<?php $SITE_URL = print_r($_POST['URL'], true); $TRIGGER_NAME = print_r($_POST['Name'], true); $STATUS = print_r($_POST['Status'], true); $result = exec(" python stcake.py $SITE_URL $TRIGGER_NAME $STATUS "); ?>
So the floor is done, the data we already get. Now it’s necessary to create tasks in Redmine when checking the site goes to the 'Down' state.
For Redmine there is a Python module that provides access to the API. Below is a script that adds tasks to the Redmine:
import sys, time from redmine import Redmine import datetime PROJECT_NAME = 'Project name' SITE_NAME = sys.argv[1] TRIGGER_STATUS = sys.argv[3] TRIGGER_NAME = sys.argv[2] REDMINE_URL = 'URL' REDMINE_KEY = 'API key' ADMINS_ID = 76 priority = 4 redmine = Redmine(REDMINE_URL, key=REDMINE_KEY) subject_name = 'Attention!!! Status Cake test: ' + TRIGGER_NAME + '. Site: ' + SITE_NAME + ' is DOWN' issueExist = redmine.issue.filter( project_id = 'Project name', subject = subject_name ) now_time = datetime.datetime.now() print issueExist print now_time print SITE_NAME print TRIGGER_NAME
Describing work with redmine-python does not make sense, it has good
documentation . I'll tell you briefly what the script does.
He checks by name whether there are already open tasks with the same name, if not, he creates a new one, and if he does, he adds a comment to this task.
Well, that's all, now with the inaccessibility of the site, we create automatic tasks in Redmine.