Ejemplo n.º 1
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
Archivo: qh.py Proyecto: ageric/merlin
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()
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
Archivo: qh.py Proyecto: op5/merlin
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()
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
Archivo: qh.py Proyecto: ageric/merlin
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)
Ejemplo n.º 11
0
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()
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
Archivo: qh.py Proyecto: op5/merlin
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)
Ejemplo n.º 16
0
def test_format_no_block():
    n = nagios_qh(None)
    result = list(n.format([]))
    assert result == [], "Unexpected result %s" % result
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
def get_merlin_nodeinfo(query_handler):
	qh = nagios_qh.nagios_qh(query_handler)
	return qh.get('#merlin nodeinfo\0')
Ejemplo n.º 19
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
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
def test_format_no_block():
    n = nagios_qh(None)
    result = list(n.format([]))
    assert result == [], "Unexpected result %s" % result