bundles/icinga2: add check_sipgate_account_balance, adjust check_interval
All checks were successful
bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2020-11-22 11:38:53 +01:00
parent 9cace7dace
commit 9651d740ae
Signed by: kunsi
GPG key ID: 12E3D2136B818350
6 changed files with 70 additions and 2 deletions

View file

@ -0,0 +1,47 @@
#!/usr/bin/env python3
from requests import get
from sys import exit
SIPGATE_USER = '${node.metadata['icinga2']['sipgate_user']}'
SIPGATE_PASS = '${node.metadata['icinga2']['sipgate_pass']}'
try:
r = get(
'https://api.sipgate.com/v2/balance',
auth=(SIPGATE_USER, SIPGATE_PASS),
headers={'Accept': 'application/json'},
)
if r.status_code == 401:
# Status code 401 means our login data is wrong. Since we're
# using the same login data in icinga_notification_wrapper, we
# won't be able to send SMS either. This should *not* result in
# this check going UNKNOWN.
print('CRITICAL: Getting the account balance failed with status code 401!')
exit(2)
else:
r.raise_for_status()
except Exception as e:
print(repr(e))
exit(3)
# No, we can't combine those two try..except blocks, because a connection
# error means the check is UNKNOWN, but a parsing error is CRITICAL.
try:
json = r.json()
money = json['amount']/10000
if money < 2:
print('CRITICAL: Only {} {} left in account!'.format(money, json['currency']))
exit(2)
elif money < 3:
print('WARNING: Only {} {} left in account!'.format(money, json['currency']))
exit(1)
else:
print('Account holds {} {}.'.format(money, json['currency']))
exit(0)
except Exception as e:
# API changed, returned malformed JSON or whatever. This is an error.
print(repr(e))
exit(2)

View file

@ -79,6 +79,13 @@ object CheckCommand "check_imap" {
}
}
object CheckCommand "check_sipgate_account_balance" {
import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ "/usr/local/share/icinga/plugins/check_sipgate_account_balance" ]
}
object CheckCommand "check_smtp" {
import "plugin-check-command"
import "ipv4-or-ipv6"