Did I find the right examples for you? yes no

All Samples(7)  |  Call(5)  |  Derive(0)  |  Import(2)
Checks the saved ouput of a run.

It returns values suitable for use as a nagios check.

:param last_run_grace: the number of seconds since the last run
    that are acceptable. If more time than this has elapsed an error
    return will be generated.
:param warn_duration: the number of seconds that the last run can
    have taken before a warning is generated. If the server responded
    successfully within the timeout, but took longer than this then a(more...)

        def check_saved_output(output, last_run_grace, warn_duration, filename):
    """Checks the saved ouput of a run.

    It returns values suitable for use as a nagios check.

    :param last_run_grace: the number of seconds since the last run
        that are acceptable. If more time than this has elapsed an error
        return will be generated.
    :param warn_duration: the number of seconds that the last run can
        have taken before a warning is generated. If the server responded
        successfully within the timeout, but took longer than this then a
        warning return will be generated.
    :returns: a tuple of (result, message) where result is a returncode
        that nagios will understand, and message is a string with more
        information.
    """
    now = time.time()
    parts = parse_output(output)
    if not parts['successful']:
        result = 2
        suffix = ' NB: Based on results stored in %r by a cronjob' % (filename,)
        result_message = "Check failed in %f: %s.%s" % (
            parts['duration'], parts['message'], suffix)
    elif parts['timestamp'] < now - last_run_grace:
        result = 2
        result_message = "Last ran %f" % (parts['timestamp'], )
    elif parts['duration'] > warn_duration:
        result = 1
        result_message = "WARN in %f: %s" % (parts['duration'], parts['message'])
    else:
        result = 0
        result_message = "OK in %f: %s" % (parts['duration'], parts['message'])
    return result, result_message
        


src/t/x/txpkgme-0.3/txpkgme/check_submit.py   txpkgme(Download)
import optparse
import os
import sys
 
from txpkgme.submitfromdisk import check_saved_output
        output = f.read()
    result, message = check_saved_output(
        output, last_run_grace, warn_duration, filename)
    sys.stdout.write(message + '\n')
    return result

src/t/x/txpkgme-0.3/txpkgme/tests/test_submitfromdisk.py   txpkgme(Download)
from twisted.web.resource import Resource
 
from txpkgme.submitfromdisk import (
    add_local_files,
    check_saved_output,
    def test_failed_with_filename(self):
        duration = 12.4
        msg = "SOME ERROR"
        result, message = check_saved_output(
            self.writer.get_output(False, duration, msg), 100, 10,
    def test_long_ago(self):
        duration = 12.4
        msg = "SOME PASS"
        result, message = check_saved_output(
            self.writer.get_output(True, duration, msg), 100, 10,
        self.clock.advance(time.time())
        result, message = check_saved_output(
            self.writer.get_output(True, duration, msg), 100, 10,
            "filename")
        self.assertEqual(1, result)
        self.clock.advance(time.time())
        result, message = check_saved_output(
            self.writer.get_output(True, duration, msg), 100, 10,
            "filename")
        self.assertEqual(0, result)