def _prepare_node_data(self, node, tmpfile): """Prepare the queue data for sending """ try: check_items = conf.get("nodes", "root").split(",") except Exception, e: rmqlogger.error("The monitor_items.conf file:%s" % str(e))
def _prepare_node_data(self, node, tmpfile): '''Prepare the queue data for sending ''' try: check_items = conf.get('nodes', 'root').split(',') except Exception, e: rmqlogger.error("The monitor_items.conf file:%s" % str(e))
def main(): '''Command-line parameters and decoding for Zabbix use/consumption. ''' choices = ['check_whole_sys', 'list_whole_sys_items',\ 'check_node', 'list_nodes', \ 'check_queue', 'list_queues', 'aliveness'] parser = optparse.OptionParser() parser.add_option('--username', help='RabbitMQ API username', default='guest') parser.add_option('--password', help='RabbitMQ API password', default='guest') parser.add_option('--hostname', help='RabbitMQ API host', default=socket.gethostname()) parser.add_option('--port', help='RabbitMQ API port', type='int', default=15672) parser.add_option('--conf', default='/etc/zabbix/zabbix_agentd.conf') parser.add_option('--check', help='Type of check', type='choice', choices=choices) parser.add_option('--node', help='Which node to check (valid for --check=server)') parser.add_option( '--metric', help='Which metric to evaluate (valid for --check=server)', default='') parser.add_option('--filters', help='Filter used queues (see README)FILTER') (options, args) = parser.parse_args() if not options.check: parser.error( 'You should specify one check type, Example: --check="xxx"!!') if options.check == 'list_queues' or options.check == 'check_queue': if not options.filters: filters = [{}] if DEBUG: rmqlogger.warning("Warn:%s List queues NO Filters!!" % options.check) else: try: filters = json.loads(options.filters) except Exception, e: rmqlogger.error("Error:%s is invalid filters object!" % (options.filters)) parser.error("Error: Invalid filters object!!") if not isinstance(filters, (list, tuple)): filters = [filters]
def main(): """Command-line parameters and decoding for Zabbix use/consumption. """ choices = [ "check_whole_sys", "list_whole_sys_items", "check_node", "list_nodes", "check_queue", "list_queues", "aliveness", ] parser = optparse.OptionParser() parser.add_option("--username", help="RabbitMQ API username", default="guest") parser.add_option("--password", help="RabbitMQ API password", default="guest") parser.add_option("--hostname", help="RabbitMQ API host", default=socket.gethostname()) parser.add_option("--port", help="RabbitMQ API port", type="int", default=15672) parser.add_option("--conf", default="/etc/zabbix/zabbix_agentd.conf") parser.add_option("--check", help="Type of check", type="choice", choices=choices) parser.add_option("--node", help="Which node to check (valid for --check=server)") parser.add_option("--metric", help="Which metric to evaluate (valid for --check=server)", default="") parser.add_option("--filters", help="Filter used queues (see README)FILTER") (options, args) = parser.parse_args() if not options.check: parser.error('You should specify one check type, Example: --check="xxx"!!') if options.check == "list_queues" or options.check == "check_queue": if not options.filters: filters = [{}] if DEBUG: rmqlogger.warning("Warn:%s List queues NO Filters!!" % options.check) else: try: filters = json.loads(options.filters) except Exception, e: rmqlogger.error("Error:%s is invalid filters object!" % (options.filters)) parser.error("Error: Invalid filters object!!") if not isinstance(filters, (list, tuple)): filters = [filters]
host_name=options.hostname, port=options.port, conf=options.conf, ) if options.check == "aliveness": print api.check_aliveness() elif options.check == "list_whole_sys_items": print json.dumps({"data": api.list_whole_sys_items()}) elif options.check == "check_whole_sys": print api.check_whole_sys() elif options.check == "list_nodes": print json.dumps({"data": api.list_nodes()}) elif options.check == "check_node": print api.check_node() elif options.check == "list_queues": print json.dumps({"data": api.list_queues(filters)}) elif options.check == "check_queue": print api.check_queue(filters) if __name__ == "__main__": conf_file = "monitor_items.conf" # import pdb;pdb.set_trace() conf = ConfigParser.ConfigParser() if os.path.exists(conf_file): conf.read("monitor_items.conf") DEBUG = int(conf.get("debug", "isLogDebug")) main() else: rmqlogger.error("The monitor_items.conf file does not exist!!")
password=options.password, host_name=options.hostname, port=options.port, conf=options.conf) if options.check == 'aliveness': print api.check_aliveness() elif options.check == 'list_whole_sys_items': print json.dumps({'data': api.list_whole_sys_items()}) elif options.check == 'check_whole_sys': print api.check_whole_sys() elif options.check == 'list_nodes': print json.dumps({'data': api.list_nodes()}) elif options.check == 'check_node': print api.check_node() elif options.check == 'list_queues': print json.dumps({'data': api.list_queues(filters)}) elif options.check == 'check_queue': print api.check_queue(filters) if __name__ == '__main__': conf_file = "monitor_items.conf" #import pdb;pdb.set_trace() conf = ConfigParser.ConfigParser() if os.path.exists(conf_file): conf.read("monitor_items.conf") DEBUG = int(conf.get('debug', 'isLogDebug')) main() else: rmqlogger.error("The monitor_items.conf file does not exist!!")