Short notes: a bunch of Redmine + StatusCake
There is such an online monitoring system StatusCake . It allows you to build fairly complex checks for sites, checks their availability, access speed, builds various beautiful graphics.
But we are not interested in this functionality, as any monitoring system, it has a mechanism for reporting problems. Notification methods are quite diverse. There is integration with various services, in particular with twitter (why ??? what to publish when the server crashes). But integration with Redmine is not there. But there is an opportunity to use webhook. Which we took advantage of. Below under the cut, what we did.
To begin with, on one of the servers where the monitoring system is located, a simple php script was located, which was called every time the server status was changed in StatusCake. This script is passed json, which in general contains:
[URL] =>
[Token] =>
[Name] =>
[StatusCode] =>
[Status] =>
- URL - this is the url for checking.
- Token is a hash of the username and API key used for verification.
- Name is the name of the test in statuscake that changed its state.
- StatusCode - the code that returned the site when accessing the specified URL.
- Status is the state 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 passes the received values. The script itself:
So the floor is done, we are already receiving data. Now you need to create tasks in Redmine when the site check goes into the 'Down' state.
There is a Python module for Redmine that provides access to the API. Below is a script that adds tasks to 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
#print TRIGGER_STATUS +": "+ TRIGGER_NAME + "\n" + ITEM_VALUE
if issueExist:
print "Issue already exist. Create comment"
issue = redmine.issue.update(
issueExist[0].id,
notes = now_time.strftime("%d.%m.%Y %I:%M %p") + ' Site: ' + SITE_NAME + ' Status: ' + TRIGGER_STATUS
)
else:
print "Issue not exist. Create issue"
issue = redmine.issue.create(
project_id = 'Project name',
subject = subject_name,
tracker_id = 3,
description = now_time.strftime("%d.%m.%Y %I:%M %p") + ' Site: ' + SITE_NAME + ' Status: ' + TRIGGER_STATUS,
status_id = 1,
priority_id = priority,
assigned_to_id =
)
It makes no sense to describe working with redmine-python, it has good documentation . I’ll tell you only 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 there is, he adds a comment to this task.
Well, that’s all, now when the site is inaccessible, tasks are created automatically in Redmine by us.