2024-04-09 21:23:07 -06:00
#!/usr/bin/env python3
import argparse
import sys
import traceback
import requests
from checker import nagios
from checker . result import quit_check
def main ( args ) :
data = { } # make pycharm happy
try :
r = requests . get ( ' http://localhost:9200/_cat/nodes?v&h=n,ip,disk*&format=json ' )
r . raise_for_status ( )
data = r . json ( ) [ 0 ]
except Exception as e :
quit_check ( f ' Failed to reach Elasticsearch: { e } ' , nagios . STATE_CRIT )
perfdata = {
' disk_used ' : {
' value ' : data [ ' disk.used ' ] ,
' min ' : 0 ,
} ,
' disk_total ' : {
' value ' : data [ ' disk.total ' ] ,
' min ' : 0 ,
} ,
' disk_avail ' : {
' value ' : data [ ' disk.avail ' ] ,
} ,
' disk_used_percent ' : {
' value ' : data [ ' disk.used_percent ' ] ,
' unit ' : ' % '
}
}
used_percent_float = float ( data [ ' disk.used_percent ' ] )
2024-04-09 21:28:58 -06:00
warn_percent = args . size_warn_percent
crit_percent = args . size_crit_percent
2024-04-09 21:23:07 -06:00
exit_str = f " { data [ ' disk.used_percent ' ] } % disk used ( { data [ ' disk.used ' ] . upper ( ) } / { data [ ' disk.total ' ] . upper ( ) } ). { data [ ' disk.avail ' ] . upper ( ) } available. "
exit_code = nagios . STATE_OK
if used_percent_float > = crit_percent :
exit_code = nagios . STATE_CRIT
elif used_percent_float > = warn_percent :
2024-04-09 21:28:58 -06:00
exit_code = nagios . STATE_WARN
2024-04-09 21:23:07 -06:00
quit_check ( exit_str , exit_code , perfdata )
if __name__ == " __main__ " :
parser = argparse . ArgumentParser ( description = ' Check the Graylog index size. ' )
parser . add_argument ( ' --size-warn-percent ' , default = 50 , type = float )
parser . add_argument ( ' --size-crit-percent ' , default = 65 , type = float )
args = parser . parse_args ( )
try :
main ( args )
except Exception as e :
print ( f ' UNKNOWN: exception " { e } " ' )
print ( traceback . format_exc ( ) )
sys . exit ( nagios . STATE_UNKNOWN )