summaryrefslogtreecommitdiff
path: root/test/nagios/support/nagios_report.py
blob: 13cd5515f20cf1e7138e1f6f61ebf91d403a12a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def functions_for_system(under_test):
    """
    returns a set of functions to use for nagios reporting:
    >>> ok, warn, critical, unknown = functions_for_system("tested system")
    
    each of them will print a nagios line with its argument and
    return the exit code:
    >>> warn("that looks strange")
    1 tested system - WARNING - that looks strange
    1
    """
    def report_function(code):
        return lambda message : report(under_test, code, message)
    return map(report_function, [0,1,2,3])

def report(system, code, message):
    codes = {0: 'OK', 1: 'WARNING', 2: 'CRITICAL', 3: 'UNKNOWN'}
    print "%d %s - %s - %s" % \
        (code, system, codes[code], message)
    return code

if __name__ == "__main__":
    import doctest
    doctest.testmod()