Commits

htgoebel committed 8f5290c

Added example for how a check_multi could collect the results.

  • Participants
  • Parent commits 1cbdb9a

Comments (0)

Files changed (1)

examples/check_multi.py

+#!/usr/bin/env python
+#
+# Copyright (C) 2011 by Hartmut Goebel <h.goebel@goebel-consult.de>
+#
+# This file is part of Shinken.
+#
+# Shinken is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# Shinken 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
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with Shinken. If not, see <http://www.gnu.org/licenses/>.
+#
+
+from shinken_plugins import *
+import shinken_plugins
+
+__copyright__ = "Copyright (C) 2011 by Hartmut Goebel"
+__licence__ = "AGPL v3+; GNU Affero General Public License version 3 or later"
+
+def check1():
+    return Result(OK, perfdata={'temperature': 27})
+check1.name = 'check1'
+
+def check2():
+    return Result(OK, perfdata={'load': (0.12, 0.3, 0.1)})
+check2.name = 'check2'
+
+def check3():
+    return Result(WARNING, 'Too much load', perfdata={'cpu': '89%'})
+check3.name = 'check3'
+
+checks = [check1, check2, check3]
+
+class check_multi(Check):
+
+    @staticmethod
+    def run(args):
+        result = Result(OK, lines=['This is only a dummy!'])
+        rcs = [0,0,0,0]
+        for i, check in enumerate(checks):
+            res = check()
+            rcs[res.rc] += 1
+            msg = shinken_plugins.rc_names[res.rc]
+            if res.message:
+                msg = ' '.join((msg, res.message))
+            res.lines.insert(0, msg)
+            res.message = None
+            for j, l in enumerate(res.lines):
+                res.lines[j] = '[%2i] %s %s' % (i, check.name, res.lines[j])
+            
+            result += res
+        result.message = '%i plugins checkes, %i critical, %i warnings, %i unknown, %i ok' % (i+1, rcs[CRITICAL], rcs[WARNING], rcs[UNKNOWN], rcs[OK])
+        return result
+
+if __name__ == '__main__':
+    __main__(check_multi)