Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
Initial release of plugin, NRPE and sudoers configuration and RPM spec
file
  • Loading branch information
stdevel committed Jun 7, 2016
1 parent 2088699 commit 61f1e32
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
5 changes: 5 additions & 0 deletions check_omd-sudo-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Make _SURE_ to check usernames and paths, depending on your Linux distribution
#Replace site with your OMD site name and nrpe with your NRPE user
#It might also be necessary to adjust the path of check_omd.py

#nrpe ALL = (site) NOPASSWD: /usr/lib64/nagios/plugins/check_omd.py
1 change: 1 addition & 0 deletions check_omd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
command[check_omd]=/usr/bin/sudo -u $ARG1$ /usr/lib64/nagios/plugins/check_omd.py
78 changes: 78 additions & 0 deletions check_omd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/python

# 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
#

from optparse import OptionParser
import subprocess
import io



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:
#check all services
fail_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":
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:
print "OK: OMD site '{0}' services are running.".format(site)
exit(0)
else:
print "CRITICAL: OMD site '{0}' has failed service(s): '{1}'".format(site, ' '.join(fail_srvs))
exit(2)



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.0.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")

#parse arguments
(options, args) = parser.parse_args()

#debug outputs
if options.debug: print "OPTIONS: {0}".format(options)

#check site status
getSiteStatus()
62 changes: 62 additions & 0 deletions nagios-plugins-check_omd.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Name: nagios-plugins-check_omd
Version: 1.0
Release: 1%{?dist}
Summary: A Nagios / Icinga plugin for checking OMD sites.

Group: Applications/System
License: GPL
URL: https://github.com/stdevel/check_omd
Source0: nagios-plugins-check_omd-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

#BuildRequires:
Requires: omd

%description
This package contains a Nagios / Icinga plugin for checking a OMD site's services.

Check out the GitHub page for further information: https://github.com/stdevel/check_omd

%prep
%setup -q

%build
#change /usr/lib64 to /usr/lib if we're on i686
%ifarch i686
sed -i -e "s/usr\/lib64/usr\/lib/" check_omd.cfg
%endif

%install
install -m 0755 -d %{buildroot}%{_libdir}/nagios/plugins/
install -m 0750 -d %{buildroot}%{_sysconfdir}/sudoers.d
install -m 0755 check_omd.py %{buildroot}%{_libdir}/nagios/plugins/check_omd.py
install -m 0440 check_omd-sudo-template %{_sysconfdir}/sudoers.d/check_omd-sudo-template
%if 0%{?el7}
install -m 0755 -d %{buildroot}%{_sysconfdir}/nrpe.d/
install -m 0755 check_omd.cfg %{buildroot}%{_sysconfdir}/nrpe.d/check_omd.cfg
%else
install -m 0755 -d %{buildroot}%{_sysconfdir}/nagios/plugins.d/
install -m 0755 check_omd.cfg %{buildroot}%{_sysconfdir}/nagios/plugins.d/check_omd.cfg
%endif

%post
echo "NOTE: Don't forget to alter /etc/sudoers.d/check_omd-sudo-template to match your OMD installation"



%clean
rm -rf $RPM_BUILD_ROOT

%files
%if 0%{?el7}
%config %{_sysconfdir}/nrpe.d/check_omd.cfg
%else
%config %{_sysconfdir}/nagios/plugins.d/check_omd.cfg
%endif
%config %{_sysconfdir}/sudoers.d/check_omd-sudo-template
%{_libdir}/nagios/plugins/check_omd.py*


%changelog
* Tue Jun 07 2016 Christian Stankowic <info@stankowic-development.net> - 1.0.1
- Initial release

0 comments on commit 61f1e32

Please sign in to comment.