https://github.com/jamespo/passinga
Push Icinga2 passive check results
https://github.com/jamespo/passinga
ansible icinga monitoring passive python
Last synced: 3 months ago
JSON representation
Push Icinga2 passive check results
- Host: GitHub
- URL: https://github.com/jamespo/passinga
- Owner: jamespo
- Created: 2022-05-02T17:39:21.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-02T17:00:28.000Z (over 1 year ago)
- Last Synced: 2025-10-14T20:35:18.181Z (8 months ago)
- Topics: ansible, icinga, monitoring, passive, python
- Language: Python
- Homepage:
- Size: 27.3 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Passinga - Icinga 2 Passive Check Script
========================================
## Install ##
Copy passinga.py into your path.
Requirements: Python 3.6+ & [urllib3](https://pypi.org/project/urllib3/) module.
## Setup ##
Create an API user just with perms to push check results:
object ApiUser "icingaapi" {
password = "3wdfkmslke"
permissions = [ "actions/process-check-result" ]
}
Create a passive service in Icinga conf:
apply Service "NinjaBackup" {
max_check_attempts = 1
retry_interval = 5m
check_interval = 5m
enable_active_checks = false
check_command = "dummy"
vars.dummy_text = "No Passive Check Result Received"
vars.dummy_state = "3"
assign where host.vars.config.backuphost
}
Pick it up in a host definition:
// dbhost.yourdomain.com
vars.config.backuphost = "1"
Configure in /etc/passinga or ~/.config/.passinga:
[Main]
icinga_url: https://icinga.yourdomain.com:5655
username: icingaapi
password: 3wdfkmslke
# set to on if you trust the cert being presented
verify_ssl: off
# this must match with the host configured for the check in Icinga
hostname: dbhost.yourdomain.com
## Usage ##
usage: passinga.py [-h] [-s {0,1,2,3}] [-n CHECKNAME] [-o EXITOUTPUT] [-m {stdin,ansible,cli}] [-f {1,2,3}]
options:
-h, --help show this help message and exit
-s EXITRC, --exitrc EXITRC
parent rc to pass in
-n CHECKNAME, --checkname CHECKNAME
Name of check
-o EXITOUTPUT, --exitoutput EXITOUTPUT
exit output
-m {stdin,ansible,cli}, --mode {stdin,ansible,cli}
-f {1,2,3}, --fixrc {1,2,3}
if exitrc non-zero value to send (1-3)
### cli mode ###
This is the default mode.
Capture your job status / output and push to Icinga in a passive check:
BACKOUTPUT=$(/usr/bin/backupjob)
BACKSTATUS=$?
passinga.py -n 'NinjaBackup' -o "$BACKOUTPUT" -s $BACKSTATUS -f 1
Note the "-f 1" flag - this "fixes" the returncode so that any code != 0 sets an Icinga RC of 1 (WARNING).
### stdin mode ###
This can be used to push the status of standard Icinga checks.
PINGSTATUS=$(mktemp)
check_ping -H 2.2.2.2 -w 80,90% -c 90,100% > $PINGSTATUS
cat $PINGSTATUS | passinga.py --mode stdin -s $? -n Ping
rm $PINGSTATUS
Intermediate step required to capture $?
### ansible mode ###
Parse the results of ansible playbooks and push to icinga:
ANSIBLE_CALLBACKS_ENABLED=json ANSIBLE_STDOUT_CALLBACK=json ansible-playbook mwsync.yml \
| tee | passinga.py --mode ansible -n "MediaWiki Sync"
A helper script "icansirun" is included suitable for cron etc which you can use as below:
CHECKNAME=backup ANSIBLE_CONFIG=/home/ansiman/conf/ansible.cfg icansirun playbook.yml