Naemon/Nagios Jenkins Checker

So this is a python program which interrogates scheduled jobs in the Jenkins automation system. It runs on the command line but the output is tailored for Nagios which uses returns codes.

./checkjenky.py -h
usage: checkjenky.py [-h] [--jobs JOBS [JOBS ...]] [--url URL] [--user USER]
                     [--password PASSWORD] [--list] [--all]

optional arguments:
  -h, --help            show this help message and exit
  --jobs JOBS [JOBS ...]
                        "Jenkins Job name"
  --url URL             Jenkins URL (default:https://jenkins:8083)
  --user USER           Jenkins user login name, (default=guest)
  --password PASSWORD   password, (default=guest)
  --list                list all the jobs on your jenkins server
  --all                 list and report on all jobs from jenkins

So you can list all jobs and then you can use that to check on individual jobs. Perhaps you need to be warned if it is disabled or it has failed.

Output would look like this:

SUCCESS, job="(directory) Sync user from IDM" is_enabled=True
FAILURE, job="(gates) Sync logs" is_enabled=True
DISABLED , job="(gecko) UAT Sync Applicants" is_enabled=False
RUNNING, job="(coursedata,quercus,docker) CMM - Load course instance fees" is_enabled=True

For Nagios/Naemon the first line is a summary line and after the output. A return code of 2 is used as a CRITCIAL result (RED) for any jobs not found in the job list; a WARNING return code (1 AMBER) for anything DISABLED (presumably because you was expecting it to be running all the time); and the rest is OK (return code 0 or GREEN) so status is RUNNING or SUCCESS.

WARNING: Job(s) DISABLED returncode 1

The code is on https://github.com/bradymd/nagios-check-jenkins-py

Leave a Reply

Your email address will not be published. Required fields are marked *