Your IP : 3.14.134.195
#!/usr/libexec/platform-python
# -*- coding: utf-8 -*-
# 2015/09/02, Eduard N.
# version 1.1
"""Nagios plugin to check status of un|installation NC ssl plugin."""
import os, re, sys
from subprocess import Popen, PIPE
log_file = '/usr/local/cpanel/logs/nc-ssl-cpanel-install.log'
version_file = '/usr/local/cpanel/3rdparty/ncssl/VERSION'
OK = 0; WARNING = 1; CRITICAL = 2; UNKNOWN = 3
re_status_critical = re.compile('[^#].* ERROR (Uni|I)nstallation: .*')
re_status_warning = re.compile('[^#].* WARNING (Uni|I)nstallation: .*')
def end(status, message, perfdata=""):
"""Exits the plugin with first arg as the return code and the second arg as the message to output."""
if perfdata:
print("{} | {}".format(message, perfdata))
else:
print("{}".format(message))
if status == OK:
sys.exit(OK)
elif status == WARNING:
sys.exit(WARNING)
elif status == CRITICAL:
sys.exit(CRITICAL)
else:
sys.exit(UNKNOWN)
status = False
if os.path.isfile(version_file):
version = open(version_file).readline().strip()
else:
version = Popen('/usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/whostmgr/cgi/ncssl/source/bin/console secrets:list -reveal |awk -e \'$1 ~ /VERSION/ {print $2}\'', stdout=PIPE, encoding="utf-8", shell=True).stdout.read()
if os.path.isfile(log_file):
for line in open(log_file):
if re.match(re_status_critical, line):
status = CRITICAL
message = line.strip()
break
elif re.match(re_status_warning, line):
status = WARNING
message = line.strip()
if status == CRITICAL:
end(status, message + ', ' + version)
elif status == WARNING:
end(status, message + ', ' + version)
else:
end(OK, "OK. File is present and no error is found, " + version)
else:
end(CRITICAL, "Log file %s doesn't exist, %s" % (log_file, version))