Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Perfdata support #1

Merged
merged 6 commits into from

2 participants

@ctd

reasonable perfdata support \o/

I haven't incremented any version numbers or nothin'.
Leaving this to you (not sure how you like your versions incremented).

@saj saj merged commit c9339dd into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 14, 2011
  1. @ctd
Commits on Jan 9, 2012
  1. @ctd
Commits on Jan 10, 2012
  1. @ctd
  2. @ctd

    update documentation/notes

    ctd authored
Commits on Jan 11, 2012
  1. @ctd

    bumped version number

    ctd authored
  2. @ctd

    update distribution packages

    ctd authored
This page is out of date. Refresh to see the latest.
View
5 README
@@ -124,11 +124,6 @@ What you probably should get for free, but don't
- Threshold helpers.
- - Perfdata helpers. (I work at sites that only use Nagios for
- availability monitoring, so this feature is unlikely to ever
- appear.)
-
-
Author
------
View
6 dist/debian/lenny/changelog
@@ -1,3 +1,9 @@
+nagioscheck (0.1.4-1) unstable; urgency=low
+
+ * New release.
+
+ -- Chris Deigan <chris@deigan.id.au> Thu, 12 Jan 2012 09:42:00 +1100
+
nagioscheck (0.1.3-1) unstable; urgency=low
* New release.
View
6 dist/debian/squeeze/changelog
@@ -1,3 +1,9 @@
+nagioscheck (0.1.4-1) unstable; urgency=low
+
+ * New release.
+
+ -- Chris Deigan <chris@deigan.id.au> Thu, 12 Jan 2012 09:42:00 +1100
+
nagioscheck (0.1.3-1) unstable; urgency=low
* New release.
View
9 dist/rpm/python-nagioscheck.spec
@@ -1,14 +1,14 @@
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
Name: python-nagioscheck
-Version: 0.1.3
+Version: 0.1.4
Release: 1%{?dist}
Summary: A Python framework for Nagios plug-in developers
Group: Development/Languages
License: BSD
URL: https://github.com/saj/pynagioscheck
-Source0: nagioscheck-0.1.3.tar.gz
+Source0: nagioscheck-0.1.4.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
@@ -18,7 +18,7 @@ BuildRequires: python-setuptools
%prep
-%setup -q -n nagioscheck-0.1.3
+%setup -q -n nagioscheck-0.1.4
%{__rm} -rf *.egg-info
%{__sed} -i 's,^#!.*env python.*$,#!/usr/bin/python,' \
setup.py
@@ -43,6 +43,9 @@ rm -rf %{buildroot}
%changelog
+* Wed Jan 11 2012 Chris Deigan <chris@deigan.id.au> - 0.1.4-1
+- New release.
+
* Tue Aug 30 2011 Saj Goonatilleke <sg@redu.cx> - 0.1.3-1
- New release.
View
51 nagioscheck.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-__version__ = '0.1.3'
+__version__ = '0.1.4'
import datetime
import gc
@@ -134,13 +134,15 @@ class Status(Exception):
Status(nagioscheck.Status.EXIT_OK, 'Happy days')
+ - Or with perfdata::
+
+ Status(nagioscheck.Status.EXIT_OK, 'Happy days',
+ PerformanceMetric('Power Level', 9001, 'points'))
+
- This, less verbose, alternative is also acceptable::
Status('ok', 'Happy days')
- Nagios perfdata is not (yet) supported. (I don't use Nagios for
- performance monitoring.)
-
"""
EXIT_OK = 0
EXIT_WARNING = 1
@@ -169,7 +171,9 @@ def __init__(self, status, msg, perfdata=None):
verbosity level 1 (`msg[1]`) is requested, the string from
`msg[0]` will be returned.
- `perfdata` is currently ignored.
+ Perfdata is optional and can be supplied as a single object or
+ a collection. PerformanceMetric exists to abstract the textual
+ formatting of the perfdata string.
"""
# This contraption generates a dictionary of valid status
@@ -226,8 +230,13 @@ def __str__(self):
return self.output()
def output(self, verbosity=0):
- return '%s: %s' % (
+ output = '%s: %s' % (
self.i_map[self.status], self.search_msg(verbosity))
+ if self.perfdata is not None:
+ output += ' |'
+ for data in self.perfdata:
+ output += ' %s' % data
+ return output
def search_msg(self, verbosity=0):
if verbosity not in range(4):
@@ -236,6 +245,36 @@ def search_msg(self, verbosity=0):
verbosity -= 1
return self.msg[verbosity]
+class PerformanceMetric:
+ """
+ Class for storing individual performance data (perfdata) metrics.
+
+
+ A collection of these objects can be passed as the perfdata
+ parameter to Status to include perfdata in your check output.
+ """
+
+ def __init__(self, label, value, unit, warning_threshold='',
+ critical_threshold='', minimum='', maximum=''):
+ self.label = label
+ self.value = value
+ self.unit = unit
+ self.warning_threshold = warning_threshold
+ self.critical_threshold = critical_threshold
+ self.minimum = minimum
+ self.maximum = maximum
+
+ def __str__(self):
+ return self.output()
+
+ def __repr__(self):
+ return self.output()
+
+ def output(self):
+ return '%s=%s%s;%s;%s;%s;%s;' % (self.label, self.value,
+ self.unit, self.warning_threshold, self.critical_threshold,
+ self.minimum, self.maximum)
+
def _handle_sigterm(signum, frame):
checks = filter(
lambda o: isinstance(o, NagiosCheck), gc.get_objects())
Something went wrong with that request. Please try again.