def test_format_one_block_one_row_two_values(): n = nagios_qh(None) result = list(n.format(["test=1;test2=13"])) assert result == [{ "test": "1", "test2": "13" }], "Unexpected result %s" % result
def test_format_two_blocks_one_row_two_values(): n = nagios_qh(None) result = list(n.format(["test", "=1", ";test2=2"])) assert result == [{ "test": "1", "test2": "2" }], "Unexpected result %s" % result
def cmd_query(args): """Run an arbitrary query with the nagios query handler. Print raw output. Commands need not include trailing nullbyte.""" handler = nagios_qh(qh) query = args_to_query(args) for block in handler.query(query): print block, sys.stdout.flush()
def test_format_one_block_two_rows_three_values(): n = nagios_qh(None) result = list(n.format(["test=1\ntest2=13;test3=42"])) assert result == [{ "test": "1" }, { "test2": "13", "test3": "42" }], "Unexpected result %s" % result
def get_merlin_nodeinfo(query_handler): def nodeinfo_sorter(a, b): if a['name'] > b['name']: return 1 if b['name'] > a['name']: return -1 return 0 qh = nagios_qh.nagios_qh(query_handler) ninfo = [] for info in qh.get('#merlin nodeinfo\0'): ninfo.append(info) ninfo.sort(nodeinfo_sorter) return ninfo
def cmd_query(args): """--socket=</path/to/query-socket> <query> Runs an arbitrary query with the nagios query handler and prints its raw output. Queries need not include the trailing nulbyte or leading hash- or at-sign. """ handler = nagios_qh(qh) query = args_to_query(args) if not query: prettyprint_docstring('query', cmd_query.__doc__, 'Not enough arguments') return for block in handler.query(query): print block, sys.stdout.flush()
def cmd_get(args): """Run an arbitrary query with the nagios query handler. Print pretty-printed output. Commands need not include trailing nullbyte.""" handler = nagios_qh(qh) query = args_to_query(args) resp = handler.query(query) try: for row in handler.format(resp): for pair in row.items(): print "%-25s %s" % pair print "" except ValueError, v: print "WARNING: Couldn't format response, printing raw response:\n" cmd_query(args)
def get_expired(query_handler): def sort(a, b): res = cmp(a['responsible'], b['responsible']) or cmp(a['responsible'], b['responsible']) if res: return res if not a.get('service_description'): return -1 if not b.get('service_description'): return 1 return a['service_description'] > b['service_description'] qh = nagios_qh.nagios_qh(query_handler) expired = [] for info in qh.get('#merlin expired\0'): expired.append(info) expired.sort(sort) return expired
def get_expired(query_handler): def sort(a, b): res = cmp(a['responsible'], b['responsible']) or cmp( a['responsible'], b['responsible']) if res: return res if not a.get('service_description'): return -1 if not b.get('service_description'): return 1 return a['service_description'] > b['service_description'] qh = nagios_qh.nagios_qh(query_handler) expired = [] for info in qh.get('#merlin expired\0'): expired.append(info) expired.sort(sort) return expired
def cmd_get(args): """--socket=</path/to/query-socket> <query> Runs an arbitrary query with the nagios query handler and pretty-prints the output. Queries need not include the trailing nulbyte or leading hash- or at-sign. """ handler = nagios_qh(qh) query = args_to_query(args) if not query: prettyprint_docstring('get', cmd_get.__doc__, 'Not enough arguments') return resp = handler.query(query) try: for row in handler.format(resp): for pair in row.items(): print "%-25s %s" % pair print "" except ValueError, v: print "WARNING: Couldn't format response, printing raw response:\n" cmd_query(args)
def test_format_no_block(): n = nagios_qh(None) result = list(n.format([])) assert result == [], "Unexpected result %s" % result
def test_format_one_block_one_row_one_value(): n = nagios_qh(None) result = list(n.format(["test=1"])) assert result == [{"test": "1"}], "Unexpected result %s" % result
def get_merlin_nodeinfo(query_handler): qh = nagios_qh.nagios_qh(query_handler) return qh.get('#merlin nodeinfo\0')
def test_format_one_block_one_row_two_values(): n = nagios_qh(None) result = list(n.format(["test=1;test2=13"])) assert result == [{"test": "1", "test2": "13"}], "Unexpected result %s" % result
def test_format_two_blocks_two_rows_two_values(): n = nagios_qh(None) result = list(n.format(["test=1", "\ntest2=2"])) assert result == [{"test": "1"}, {"test2": "2"}], "Unexpected result %s" % result
def test_format_two_blocks_one_row_one_value(): n = nagios_qh(None) result = list(n.format(["test", "=1"])) assert result == [{"test": "1"}], "Unexpected result %s" % result
def test_format_one_block_two_rows_three_values(): n = nagios_qh(None) result = list(n.format(["test=1\ntest2=13;test3=42"])) assert result == [{"test": "1"}, {"test2": "13", "test3": "42"}], "Unexpected result %s" % result