Exemple #1
0
    def check_queue(self, filters=None):
        """Return the value for a specific item in a queue's details.
        """
        return_code = 0
        if not filters:
            filters = [{}]

        rdatafile = tempfile.NamedTemporaryFile(delete=False)
        for queue in self.call_api("queues"):
            success = False
            for _filter in filters:
                check = [(x, y) for x, y in queue.items() if x in _filter]
                shared_items = set(_filter.items()).intersection(check)
                if len(shared_items) == len(_filter):
                    success = True
                    break
            if success:
                self._prepare_queue_data(queue, rdatafile)
        if DEBUG:
            rdatafile.seek(0)
            rmqlogger.info("\n" + rdatafile.read())
        rdatafile.close()
        return_code |= self._send_data(rdatafile)
        os.unlink(rdatafile.name)
        return return_code
Exemple #2
0
    def check_queue(self, filters=None):
        '''Return the value for a specific item in a queue's details.
        '''
        return_code = 0
        if not filters:
            filters = [{}]

        rdatafile = tempfile.NamedTemporaryFile(delete=False)
        for queue in self.call_api('queues'):
            success = False
            for _filter in filters:
                check = [(x, y) for x, y in queue.items() if x in _filter]
                shared_items = set(_filter.items()).intersection(check)
                if len(shared_items) == len(_filter):
                    success = True
                    break
            if success:
                self._prepare_queue_data(queue, rdatafile)
        if DEBUG:
            rdatafile.seek(0)
            rmqlogger.info("\n" + rdatafile.read())
        rdatafile.close()
        return_code |= self._send_data(rdatafile)
        os.unlink(rdatafile.name)
        return return_code
Exemple #3
0
 def list_whole_sys_items(self):
     """ List the system items name for zabbix discovery to use!
     """
     items = []
     for tup in conf.items("whole_sys_items"):
         for item in tup[1].split(","):
             element = {"{#ITEMNAME}": item}
             items.append(element)
     if DEBUG:
         rmqlogger.info(items)
     return items
Exemple #4
0
 def list_whole_sys_items(self):
     ''' List the system items name for zabbix discovery to use!
     '''
     items = []
     for tup in conf.items("whole_sys_items"):
         for item in tup[1].split(','):
             element = {'{#ITEMNAME}': item}
             items.append(element)
     if DEBUG:
         rmqlogger.info(items)
     return items
Exemple #5
0
 def list_nodes(self):
     """Lists all rabbitMQ nodes in the cluster
     """
     nodes = []
     for node in self.call_api("nodes"):
         # We need to return the node name, because Zabbix
         # does not support @ as an item paramater
         name = node["name"].split("@")[1]
         type = node["type"]
         element = {"{#NODENAME}": name, "{#NODETYPE}": type}
         nodes.append(element)
     if DEBUG:
         rmqlogger.info(nodes)
     return nodes
Exemple #6
0
 def list_nodes(self):
     '''Lists all rabbitMQ nodes in the cluster
     '''
     nodes = []
     for node in self.call_api('nodes'):
         # We need to return the node name, because Zabbix
         # does not support @ as an item paramater
         name = node['name'].split('@')[1]
         type = node['type']
         element = {'{#NODENAME}': name, '{#NODETYPE}': type}
         nodes.append(element)
     if DEBUG:
         rmqlogger.info(nodes)
     return nodes
Exemple #7
0
 def check_whole_sys(self):
     """get item value to save in a file,
        use zabbix_sender to active send the key value
     """
     return_code = 0
     rdatafile = tempfile.NamedTemporaryFile(delete=False)
     overview = self.call_api("overview")
     self._prepare_whole_sys_data(overview, rdatafile)
     if DEBUG:
         rdatafile.seek(0)
         rmqlogger.info(rdatafile.read())
     rdatafile.close()
     return_code |= self._send_data(rdatafile)
     os.unlink(rdatafile.name)
     return return_code
Exemple #8
0
    def check_node(self):
        """Return the value for a specific item in a node's details.
        """
        return_code = 0
        rdatafile = tempfile.NamedTemporaryFile(delete=False)
        for node in self.call_api("nodes"):
            self._prepare_node_data(node, rdatafile)

        if DEBUG:
            rdatafile.seek(0)
            rmqlogger.info("\n" + rdatafile.read())
        rdatafile.close()
        return_code |= self._send_data(rdatafile)
        os.unlink(rdatafile.name)
        return return_code
Exemple #9
0
 def check_whole_sys(self):
     '''get item value to save in a file,
        use zabbix_sender to active send the key value
     '''
     return_code = 0
     rdatafile = tempfile.NamedTemporaryFile(delete=False)
     overview = self.call_api('overview')
     self._prepare_whole_sys_data(overview, rdatafile)
     if DEBUG:
         rdatafile.seek(0)
         rmqlogger.info(rdatafile.read())
     rdatafile.close()
     return_code |= self._send_data(rdatafile)
     os.unlink(rdatafile.name)
     return return_code
Exemple #10
0
    def check_node(self):
        '''Return the value for a specific item in a node's details.
        '''
        return_code = 0
        rdatafile = tempfile.NamedTemporaryFile(delete=False)
        for node in self.call_api('nodes'):
            self._prepare_node_data(node, rdatafile)

        if DEBUG:
            rdatafile.seek(0)
            rmqlogger.info("\n" + rdatafile.read())
        rdatafile.close()
        return_code |= self._send_data(rdatafile)
        os.unlink(rdatafile.name)
        return return_code
Exemple #11
0
 def _send_data(self, tmpfile):
     """Send the key-value file data to Zabbix.
     """
     args = "zabbix_sender -c {0} -i {1}"
     return_code = 0
     if DEBUG:
         p = subprocess.Popen(
             args.format(self.conf, tmpfile.name), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
         )
         return_code = p.wait()
         rmqlogger.info("Return Code: %s\nMessage:%s" % (return_code, p.stdout.read()))
     else:
         return_code |= subprocess.call(
             args.format(self.conf, tmpfile.name), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
         )
     return return_code
Exemple #12
0
 def list_queues(self, filters=None):
     """
     List all of the RabbitMQ queues, filtered against the filters provided
     in .rab.auth. See README.md for more information.
     """
     queues = []
     if not filters:
         filters = [{}]
     for queue in self.call_api("queues"):
         for _filter in filters:
             check = [(x, y) for x, y in queue.items() if x in _filter]
             shared_items = set(_filter.items()).intersection(check)
             if len(shared_items) == len(_filter):
                 element = {"{#VHOSTNAME}": queue["vhost"], "{#QUEUENAME}": queue["name"]}
                 queues.append(element)
                 break
     if DEBUG:
         rmqlogger.info(queues)
     return queues
Exemple #13
0
 def _send_data(self, tmpfile):
     '''Send the key-value file data to Zabbix.
     '''
     args = 'zabbix_sender -c {0} -i {1}'
     return_code = 0
     if DEBUG:
         p = subprocess.Popen(args.format(self.conf, tmpfile.name),
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
         return_code = p.wait()
         rmqlogger.info("Return Code: %s\nMessage:%s" %
                        (return_code, p.stdout.read()))
     else:
         return_code |= subprocess.call(args.format(self.conf,
                                                    tmpfile.name),
                                        shell=True,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)
     return return_code
Exemple #14
0
 def list_queues(self, filters=None):
     '''
     List all of the RabbitMQ queues, filtered against the filters provided
     in .rab.auth. See README.md for more information.
     '''
     queues = []
     if not filters:
         filters = [{}]
     for queue in self.call_api('queues'):
         for _filter in filters:
             check = [(x, y) for x, y in queue.items() if x in _filter]
             shared_items = set(_filter.items()).intersection(check)
             if len(shared_items) == len(_filter):
                 element = {
                     '{#VHOSTNAME}': queue['vhost'],
                     '{#QUEUENAME}': queue['name']
                 }
                 queues.append(element)
                 break
     if DEBUG:
         rmqlogger.info(queues)
     return queues