mirror of
https://github.com/ranl/monitor-utils.git
synced 2024-11-22 15:33:43 +01:00
change modjk nagios plugin
This commit is contained in:
parent
ae93696f89
commit
1d86cb3b2e
@ -7,6 +7,7 @@ requires
|
|||||||
- Python >= 2.6
|
- Python >= 2.6
|
||||||
- status worker enable
|
- status worker enable
|
||||||
'''
|
'''
|
||||||
|
from numpy.core.memmap import memmap
|
||||||
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import urllib2
|
import urllib2
|
||||||
@ -19,13 +20,14 @@ EXIT_CODE = {
|
|||||||
'UNKNOWN': 3,
|
'UNKNOWN': 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
def prepareOpts():
|
|
||||||
|
def prepare_opts():
|
||||||
'''
|
'''
|
||||||
Parse option from the shell
|
Parse option from the shell
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def help():
|
def help():
|
||||||
print 'How many workers are in a non-OK state'
|
print 'How many workers are in OK state and Activated'
|
||||||
print ''
|
print ''
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
@ -44,33 +46,37 @@ def prepareOpts():
|
|||||||
# Input Validation
|
# Input Validation
|
||||||
if not opts.url:
|
if not opts.url:
|
||||||
err('missing Modjk Status http url')
|
err('missing Modjk Status http url')
|
||||||
if opts.warning > opts.critical:
|
if opts.warning < opts.critical:
|
||||||
err('-w can not be greater than -c')
|
err('-w can not be smaller than -c')
|
||||||
if opts.warning < 0 or opts.critical < 0:
|
if opts.warning < 0 or opts.critical < 0:
|
||||||
err('-w and -c must be a positive number')
|
err('-w and -c must be a positive number')
|
||||||
|
|
||||||
return opts
|
return opts
|
||||||
|
|
||||||
def getErrorWorkers(url, timeout):
|
|
||||||
|
def get_error_workers(url, timeout):
|
||||||
'''
|
'''
|
||||||
Query the Modjk status worker for bad workers
|
Query the Modjk status worker for bad workers
|
||||||
'''
|
'''
|
||||||
|
|
||||||
ret = []
|
get_node = re.compile(r'Member: name=(.*) type=')
|
||||||
response = urllib2.urlopen(url+'?command=list&mime=prop', timeout=timeout).read()
|
ret = set([])
|
||||||
for line in re.findall( r'worker\..*\.state=.*', response, re.M):
|
total = 0
|
||||||
if not line.endswith('OK'):
|
response = urllib2.urlopen(url+'?mime=txt', timeout=timeout).read()
|
||||||
ret.append(
|
for member in re.findall( r'^Member: .*', response, re.M):
|
||||||
line.split('.',1)[1].split('.',1)[0]
|
total += 1
|
||||||
|
if 'state=OK' in member and 'activation=ACT' in member:
|
||||||
|
ret.add(
|
||||||
|
get_node.search(member).groups(0)[0]
|
||||||
)
|
)
|
||||||
return ret
|
return (list(ret), total)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
opts = prepareOpts()
|
opts = prepare_opts()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
errorWorkers = getErrorWorkers(
|
(errorWorkers, total) = get_error_workers(
|
||||||
opts.url, opts.timeout
|
opts.url, opts.timeout
|
||||||
)
|
)
|
||||||
except urllib2.URLError as e:
|
except urllib2.URLError as e:
|
||||||
@ -79,14 +85,14 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
count = len(errorWorkers)
|
count = len(errorWorkers)
|
||||||
state = ''
|
state = ''
|
||||||
if count < opts.warning:
|
if count > opts.warning:
|
||||||
state = 'OK'
|
state = 'OK'
|
||||||
elif count >= opts.warning and count < opts.critical:
|
elif opts.warning >= count > opts.critical:
|
||||||
state = 'WARN'
|
state = 'WARN'
|
||||||
else:
|
else:
|
||||||
state = 'CRIT'
|
state = 'CRIT'
|
||||||
|
|
||||||
print '{0}: {1} workers are in Err state {2}'.format(
|
print '{0}: {1}/{2} workers are OK and ACT {3}'.format(
|
||||||
state, count, ','.join(errorWorkers)
|
state, count, total, ','.join(errorWorkers)
|
||||||
)
|
)
|
||||||
exit(EXIT_CODE[state])
|
exit(EXIT_CODE[state])
|
||||||
|
Loading…
Reference in New Issue
Block a user