From ad16f4f7299938afb068d1b5e5cb0f09d21455ff Mon Sep 17 00:00:00 2001 From: Tomas Edwardsson Date: Wed, 5 Jun 2013 14:33:26 +0000 Subject: [PATCH] Automatic commit of package [nagios-okplugin-check_ifoperstate] release [0.0.2-1]. --- check_http_multi/check_http_multi | 89 +++++++++++++++++++ .../nagios-okplugin-check_ifoperstate.spec | 5 +- .../nagios-okplugin-check_ifoperstate | 1 + 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 check_http_multi/check_http_multi create mode 100644 rel-eng/packages/nagios-okplugin-check_ifoperstate diff --git a/check_http_multi/check_http_multi b/check_http_multi/check_http_multi new file mode 100644 index 0000000..9f4abfb --- /dev/null +++ b/check_http_multi/check_http_multi @@ -0,0 +1,89 @@ +#!/usr/bin/python +# Copyright 2013, Tomas Edwardsson +# +# This script is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from pynag.Plugins import PluginHelper, critical, warning, ok +import requests +import time +import signal + + +class TimeoutException(Exception): + pass + + +def signal_alarm(signo, frame): + raise TimeoutException() + + +def main(): + plugin = PluginHelper() + + plugin.parser.add_option('-u', help="http uris", dest="uri", action="append") + plugin.parse_arguments() + + if not plugin.options.uri: + plugin.parser.error("-u (uri) argument is required") + + start_time = time.time() + # Assign timeout handler + signal.signal(signal.SIGALRM, signal_alarm) + + success = 0 + failed = 0 + for uri in plugin.options.uri: + webstate, status = check_website(uri) + if webstate: + success += 1 + plugin.add_long_output("%s fetched in %s seconds" % (uri, status)) + plugin.add_metric(uri, status, uom="s") + + else: + failed += 1 + plugin.add_long_output("%s failed, %s" % (uri, status)) + + plugin.add_summary("Checked %i uris, %i failed" % ((failed + success), failed)) + plugin.status(ok) + plugin.add_metric("failed", failed) + plugin.add_metric("failed_percentage", (100 * failed / float(failed + success)), uom="%") + plugin.add_metric("runtime", time.time() - start_time, uom="s") + plugin.check_all_metrics() + + plugin.exit() + + + +def check_website(uri, timeout=10): + """Tries fetching the uri specified + returns (False, "Invalid status code ") on any failure and status code other than 2XX + returns (None, "Timeout in %f seconds") on timeout + returns (True, time (float)) it took to fetch the website on success""" + + start_time = time.time() + signal.alarm(timeout) + try: + req = requests.get(uri) + if str(req.status_code)[0] != "2": + return False, "Invalid HTTP status: " + str(req.status_code) + except TimeoutException: + return None, "Timeout in %.2f seconds" % (time.time() - start_time) + except Exception, e: + return False, "Error encountered: " + e.message + signal.alarm(0) + return True, "%.2f" % (time.time() - start_time) + + +if __name__ == "__main__": + main() diff --git a/check_ifoperstate/nagios-okplugin-check_ifoperstate.spec b/check_ifoperstate/nagios-okplugin-check_ifoperstate.spec index e425922..f3c1a69 100644 --- a/check_ifoperstate/nagios-okplugin-check_ifoperstate.spec +++ b/check_ifoperstate/nagios-okplugin-check_ifoperstate.spec @@ -3,7 +3,7 @@ Summary: A Nagios plugin to check interface operator status Name: nagios-okplugin-%{plugin} -Version: 0.0.1 +Version: 0.0.2 Release: 1%{?dist} License: GPLv2+ Group: Applications/System @@ -37,3 +37,6 @@ rm -rf %{buildroot} %{_libdir}/nagios/plugins/* %changelog +* Wed Jun 05 2013 Tomas Edwardsson 0.0.2-1 +- new package built with tito + diff --git a/rel-eng/packages/nagios-okplugin-check_ifoperstate b/rel-eng/packages/nagios-okplugin-check_ifoperstate new file mode 100644 index 0000000..86b6c4b --- /dev/null +++ b/rel-eng/packages/nagios-okplugin-check_ifoperstate @@ -0,0 +1 @@ +0.0.2-1 check_ifoperstate/