-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Icinga2 configuration, bumped RPM spec file, cleaned-up code
- Loading branch information
Showing
4 changed files
with
161 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
object CheckCommand "check_omd" { | ||
import "plugin-check-command" | ||
command = [ "sudo", "-u", "$omd_site$", PluginDir + "/check_omd.py" ] | ||
|
||
arguments = { | ||
"-x" = { | ||
value = "$omd_exclude_service$" | ||
description = "services that should be excluded (default: none)" | ||
} | ||
"-w" = { | ||
set_if = "$omd_warning_service$" | ||
description = "services that only should throw a warning if not running (useful for fragile stuff like npcd, default: none)" | ||
} | ||
"-d" = { | ||
set_if = "$omd_debug$" | ||
description = "enable debugging outputs (default: no)" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,144 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# check_omd.py - a script for checking a particular | ||
# OMD site status | ||
# | ||
# 2016 By Christian Stankowic | ||
# <info at stankowic hyphen development dot net> | ||
# https://github.com/stdevel | ||
# | ||
""" | ||
check_omd.py - a script for checking a particular | ||
OMD site status | ||
2018 By Christian Stankowic | ||
<info at cstan dot io> | ||
https://github.com/stdevel/check_omd | ||
""" | ||
|
||
from optparse import OptionParser | ||
import subprocess | ||
import io | ||
import logging | ||
|
||
__version__ = "1.1.1" | ||
""" | ||
str: Program version | ||
""" | ||
LOGGER = logging.getLogger('check_omd') | ||
""" | ||
logging: Logger instance | ||
""" | ||
|
||
|
||
|
||
def get_site_status(): | ||
""" | ||
Retrieves a particular site's status | ||
""" | ||
#get username | ||
proc = subprocess.Popen("whoami", stdout=subprocess.PIPE) | ||
site = proc.stdout.read().rstrip() | ||
LOGGER.debug("It seems like I'm OMD site '%s'", site) | ||
|
||
def getSiteStatus(): | ||
#get username | ||
proc = subprocess.Popen("whoami", stdout=subprocess.PIPE) | ||
site = proc.stdout.read().rstrip() | ||
if options.debug: print "DEBUG: It seems like I'm OMD site '{0}'".format(site) | ||
|
||
#get OMD site status | ||
cmd = ['omd', 'status', '-b'] | ||
if options.debug: print "DEBUG: running command '{0}'".format(cmd) | ||
proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | ||
res, err = proc.communicate() | ||
|
||
if err: | ||
if "no such site" in err: | ||
print "UNKNOWN: unable to check site: '{0}' - did you miss running this plugin as OMD site user?".format(err.rstrip()) | ||
else: | ||
print "UNKNOWN: unable to check site: '{0}'".format(err.rstrip()) | ||
exit(3) | ||
if res: | ||
#try to find out whether omd was executed as root | ||
if res.count("OVERALL") > 1: | ||
print "UNKOWN: unable to check site, it seems this plugin is executed as root (use OMD site context!)" | ||
exit(3) | ||
|
||
#check all services | ||
fail_srvs=[] | ||
warn_srvs=[] | ||
if options.debug: print "DEBUG: Got result '{0}'".format(res) | ||
for line in io.StringIO(res.decode('utf-8')): | ||
service = line.rstrip().split(" ")[0] | ||
status = line.rstrip().split(" ")[1] | ||
if service not in options.exclude: | ||
#check service | ||
if status != "0": | ||
if service in options.warning: | ||
if options.debug: print "{0} service marked for warning has failed state ({1})".format(service, status) | ||
warn_srvs.append(service) | ||
else: | ||
fail_srvs.append(service) | ||
if options.debug: print "{0} service has failed state ({1})".format(service, status) | ||
else: | ||
if options.debug: print "Ignoring '{0}' as it's blacklisted...".format(service) | ||
if len(fail_srvs) == 0 and len(warn_srvs) == 0: | ||
print "OK: OMD site '{0}' services are running.".format(site) | ||
exit(0) | ||
elif len(fail_srvs) > 0: | ||
print "CRITICAL: OMD site '{0}' has failed service(s): '{1}'".format(site, ' '.join(fail_srvs)) | ||
exit(2) | ||
else: | ||
print "WARNING: OMD site '{0}' has service(s) in warning state: '{1}'".format(site, ' '.join(warn_srvs)) | ||
exit(1) | ||
#get OMD site status | ||
cmd = ['omd', 'status', '-b'] | ||
LOGGER.debug("running command '%s'", cmd) | ||
proc = subprocess.Popen( | ||
cmd, stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE | ||
) | ||
res, err = proc.communicate() | ||
|
||
if err: | ||
if "no such site" in err: | ||
print "UNKNOWN: unable to check site: '{0}' - did you miss " \ | ||
"running this plugin as OMD site user?".format(err.rstrip()) | ||
else: | ||
print "UNKNOWN: unable to check site: '{0}'".format(err.rstrip()) | ||
exit(3) | ||
if res: | ||
#try to find out whether omd was executed as root | ||
if res.count("OVERALL") > 1: | ||
print "UNKOWN: unable to check site, it seems this plugin is " \ | ||
"executed as root (use OMD site context!)" | ||
exit(3) | ||
|
||
#check all services | ||
fail_srvs = [] | ||
warn_srvs = [] | ||
LOGGER.debug("Got result '%s'", res) | ||
for line in io.StringIO(res.decode('utf-8')): | ||
service = line.rstrip().split(" ")[0] | ||
status = line.rstrip().split(" ")[1] | ||
if service not in OPTIONS.exclude: | ||
#check service | ||
if status != "0": | ||
if service in OPTIONS.warning: | ||
LOGGER.debug( | ||
"%s service marked for warning has failed" \ | ||
" state (%s)", service, status | ||
) | ||
warn_srvs.append(service) | ||
else: | ||
fail_srvs.append(service) | ||
LOGGER.debug( | ||
"%s service has failed state " \ | ||
"(%s)", service, status | ||
) | ||
else: | ||
LOGGER.debug( | ||
"Ignoring '%s' as it's blacklisted.", service | ||
) | ||
if len(fail_srvs) == 0 and len(warn_srvs) == 0: | ||
print "OK: OMD site '{0}' services are running.".format(site) | ||
exit(0) | ||
elif len(fail_srvs) > 0: | ||
print "CRITICAL: OMD site '{0}' has failed service(s): " \ | ||
"'{1}'".format(site, ' '.join(fail_srvs)) | ||
exit(2) | ||
else: | ||
print "WARNING: OMD site '{0}' has service(s) in warning state: " \ | ||
"'{1}'".format(site, ' '.join(warn_srvs)) | ||
exit(1) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
#define description, version and load parser | ||
desc='''%prog is used to check a particular OMD site status. By default, the script only checks a site's overall status. It is also possible to exclude particular services and only check the remaining services (e.g. rrdcached, npcd, icinga, apache, crontab). | ||
Checkout the GitHub page for updates: https://github.com/stdevel/check_omd''' | ||
parser = OptionParser(description=desc,version="%prog version 1.1.0") | ||
|
||
#-d / --debug | ||
parser.add_option("-d", "--debug", dest="debug", default=False, action="store_true", help="enable debugging outputs") | ||
|
||
#-e / --exclude | ||
parser.add_option("-x", "--exclude", dest="exclude", default=["OVERALL"], action="append", metavar="SERVICE", help="defines one or more services that should be excluded") | ||
|
||
#-w / --warning | ||
parser.add_option("-w", "--warning", dest="warning", default=[""], action="append", metavar="SERVICE", help="defines one or more services that only should throw a warning if not running (useful for fragile stuff like npcd)") | ||
|
||
#parse arguments | ||
(options, args) = parser.parse_args() | ||
|
||
#debug outputs | ||
if options.debug: print "OPTIONS: {0}".format(options) | ||
|
||
#check site status | ||
getSiteStatus() | ||
#define description, version and load parser | ||
DESC = '''%prog is used to check a particular OMD site status. By default, | ||
the script only checks a site's overall status. It is also possible to exclude | ||
particular services and only check the remaining services (e.g. rrdcached, | ||
npcd, icinga, apache, crontab). | ||
Checkout the GitHub page for updates: https://github.com/stdevel/check_omd''' | ||
PARSER = OptionParser(description=DESC, version=__version__) | ||
|
||
#-d / --debug | ||
PARSER.add_option( | ||
"-d", "--debug", dest="debug", default=False, action="store_true", | ||
help="enable debugging outputs (default: no)" | ||
) | ||
|
||
#-e / --exclude | ||
PARSER.add_option( | ||
"-x", "--exclude", dest="exclude", default=["OVERALL"], | ||
action="append", metavar="SERVICE", help="defines one or more " \ | ||
"services that should be excluded (default: none)" | ||
) | ||
|
||
#-w / --warning | ||
PARSER.add_option( | ||
"-w", "--warning", dest="warning", default=[""], action="append", | ||
metavar="SERVICE", help="defines one or more services that only " \ | ||
"should throw a warning if not running (useful for fragile stuff " \ | ||
"like npcd, default: none)" | ||
) | ||
|
||
#parse arguments | ||
(OPTIONS, ARGS) = PARSER.parse_args() | ||
|
||
#set logging level | ||
logging.basicConfig() | ||
if OPTIONS.debug: | ||
LOGGER.setLevel(logging.DEBUG) | ||
else: | ||
LOGGER.setLevel(logging.ERROR) | ||
|
||
LOGGER.debug("OPTIONS: %s", OPTIONS) | ||
|
||
#check site status | ||
get_site_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
name: check_omd | ||
description: "file:///README.md" | ||
url: "https://github.com/stdevel/check_omd" | ||
tags: OMD,Nagios,Icinga | ||
tags: OMD,Nagios,Icinga,Icinga2 | ||
vendor: Linux | ||
target: Operating System | ||
type: Plugin | ||
license: gplv3 | ||
releases: | ||
- | ||
name: 1.1.0 | ||
description: "1.1.0 Release" | ||
name: 1.1.1 | ||
description: "Release 1.1.1" | ||
files: | ||
- | ||
name: check_omd.py | ||
url: "file:///check_omd.py" | ||
description: "Initial release" | ||
checksum: df76dfdeedb07b8c7df52ae621b57c19 | ||
description: "Release 1.1.1" | ||
checksum: 17235ca90db9bd7d94988c847de67418 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters