当前位置: 首页>>代码示例>>Python>>正文


Python pyzabbix.ZabbixSender类代码示例

本文整理汇总了Python中pyzabbix.ZabbixSender的典型用法代码示例。如果您正苦于以下问题:Python ZabbixSender类的具体用法?Python ZabbixSender怎么用?Python ZabbixSender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ZabbixSender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_response_fail_s_close

    def test_get_response_fail_s_close(self, mock_socket):
        mock_socket.recv.side_effect = (b'IDDQD', self.resp_body)
        mock_socket.close.side_effect = Exception

        zs = ZabbixSender()
        result = zs._get_response(mock_socket)
        self.assertFalse(result)
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:7,代码来源:test_sender.py

示例2: test_create_messages

 def test_create_messages(self):
     m = [ZabbixMetric('host1', 'key1', 1),
          ZabbixMetric('host2', 'key2', 2)]
     zs = ZabbixSender()
     result = zs._create_messages(m)
     self.assertIsInstance(result, list)
     self.assertEqual(len(result), 2)
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:7,代码来源:test_sender.py

示例3: test_get_response

    def test_get_response(self, mock_socket):
        mock_socket.recv.side_effect = (self.resp_header, self.resp_body)

        zs = ZabbixSender()
        result = zs._get_response(mock_socket)
        mock_socket.recv.assert_has_calls([call(92)])
        self.assertEqual(result['response'], 'success')
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:7,代码来源:test_sender.py

示例4: configure

    def configure(self, configuration):
        BaseThreadedModule.configure(self, configuration)
        self.hostname = self.getConfigurationValue("hostname")
        self.fields = self.getConfigurationValue("fields")
        self.field_prefix = self.getConfigurationValue("field_prefix")
        self.timestamp_field = self.getConfigurationValue("timestamp_field")
        self.batch_size = self.getConfigurationValue('batch_size')
        self.backlog_size = self.getConfigurationValue('backlog_size')
        self.agent_conf = self.getConfigurationValue("agent_conf")
        if self.agent_conf:
            if self.agent_conf is True:
                self.agent_conf = "/etc/zabbix/zabbix_agentd.conf"
            if not os.path.isfile(self.agent_conf):
                self.logger.error("%s does not point to an existing file." % self.agent_conf)
                self.lumbermill.shutDown()
            self.zabbix_sender = ZabbixSender(use_config=self.agent_conf)

        else:
            self.logger.error("asdads")
            server = self.getConfigurationValue("server")
            port = 10051
            if ":" in self.server:
                server, port = self.server.split(":")
            self.zabbix_sender = ZabbixSender(zabbix_server=server, port=port)
        self.buffer = Buffer(self.getConfigurationValue('batch_size'), self.storeData,
                             self.getConfigurationValue('store_interval_in_secs'),
                             maxsize=self.getConfigurationValue('backlog_size'))
开发者ID:dstore-dbap,项目名称:LumberMill,代码行数:27,代码来源:ZabbixSink.py

示例5: test_send_sendall_exception

    def test_send_sendall_exception(self, mock_socket):
        mock_socket.return_value = mock_socket
        mock_socket.sendall.side_effect = Exception

        zm = ZabbixMetric('host1', 'key1', 100500, 1457358608)
        zs = ZabbixSender()
        with self.assertRaises(Exception):
            zs.send([zm])
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:8,代码来源:test_sender.py

示例6: test_recive

    def test_recive(self, mock_socket):
        mock_data = b'\x01\\\x00\x00\x00\x00\x00\x00\x00'
        mock_socket.recv.side_effect = (False, b'ZBXD', mock_data)

        zs = ZabbixSender()
        result = zs._receive(mock_socket, 13)
        self.assertEqual(result, b'ZBXD' + mock_data)
        self.assertEqual(mock_socket.recv.call_count, 3)
        mock_socket.recv.assert_has_calls([call(13), call(13), call(9)])
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:9,代码来源:test_sender.py

示例7: test_send

    def test_send(self, mock_socket):
        mock_data = b'\x01\\\x00\x00\x00\x00\x00\x00\x00'
        mock_socket.return_value = mock_socket
        mock_socket.recv.side_effect = (b'ZBXD', mock_data, self.resp_body)

        zm = ZabbixMetric('host1', 'key1', 100500, 1457358608)
        zs = ZabbixSender()
        result = zs.send([zm])
        self.assertTrue(result)
开发者ID:ningning992,项目名称:py-zabbix,代码行数:9,代码来源:test_sender.py

示例8: test_create_request_failed

 def test_create_request_failed(self):
     message = [
         '{"clock": "1457445366", "host: \
         "host1", "value": "1", "key": "key1"}',
         '{"clock": "1457445366", "host": \
         "host2", "value": "2", "key": "key2"}']
     zs = ZabbixSender()
     result = zs._create_request(message)
     with self.assertRaises(Exception):
         result = json.loads(result.decode())
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:10,代码来源:test_sender.py

示例9: test_send

    def test_send(self, mock_socket):
        mock_data = b'\x01\\\x00\x00\x00\x00\x00\x00\x00'
        mock_socket.return_value = mock_socket
        mock_socket.recv.side_effect = (b'ZBXD', mock_data, self.resp_body)

        zm = ZabbixMetric('host1', 'key1', 100500, 1457358608)
        zs = ZabbixSender()
        result = zs.send([zm])
        self.assertIsInstance(result, ZabbixResponse)
        self.assertEqual(result.chunk, 1)
        self.assertEqual(result.total, 10)
        self.assertEqual(result.failed, 10)
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:12,代码来源:test_sender.py

示例10: test_create_request

 def test_create_request(self):
     message = [
         '{"clock": "1457445366", "host": "host1",\
         "value": "1", "key": "key1"}',
         '{"clock": "1457445366", "host": "host2",\
         "value": "2", "key": "key2"}']
     zs = ZabbixSender()
     result = zs._create_request(message)
     self.assertIsInstance(result, bytes)
     result = json.loads(result.decode())
     self.assertEqual(result['request'], 'sender data')
     self.assertEqual(len(result['data']), 2)
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:12,代码来源:test_sender.py

示例11: test_send_failed

    def test_send_failed(self, mock_socket):
        mock_data = b'\x01\\\x00\x00\x00\x00\x00\x00\x00'
        mock_socket.return_value = mock_socket
        mock_socket.recv.side_effect = (b'ZBXD', mock_data, b'''
{"response": "suces","info":"processed: 0; failed: \
10; total: 10; seconds spent: 0.000078"}
''')

        zm = ZabbixMetric('host1', 'key1', 100500, 1457358608)
        zs = ZabbixSender()
        with self.assertRaises(Exception):
            zs.send([zm])
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:12,代码来源:test_sender.py

示例12: test_create_packet

 def test_create_packet(self):
     message = [
         '{"clock": "1457445366", "host": "host1",\
         "value": "1", "key": "key1"}',
         '{"clock": "1457445366", "host": "host2",\
         "value": "2", "key": "key2"}']
     zs = ZabbixSender()
     request = zs._create_request(message)
     result = zs._create_packet(request)
     data_len = struct.pack('<Q', len(request))
     self.assertEqual(result[5:13], data_len)
     self.assertEqual(result[:13],
                      b'ZBXD\x01\xc4\x00\x00\x00\x00\x00\x00\x00')
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:13,代码来源:test_sender.py

示例13: trapper

def trapper(items_raw):
    if dict_setup["metric_sent_protocol"].lower() == "zabbix":
        hostname = dict_setup["metric_sent_hostname"].lower()
        zabbix_server = dict_setup["metric_sent_server"].lower()
        try:
            timestamp = items_raw['timestamp']
            metrics = []
            zbx = ZabbixSender(zabbix_server)
            for metric in items_raw:
                if metric != "timestamp":
                    m = ZabbixMetric(host=hostname, key=metric, value=items_raw[metric], clock=timestamp)
                    metrics.append(m)
            returapi = zbx.send(metrics)
            logging.info("{}: {}".format(inspect.stack()[1][3], returapi))
            return True
        except Exception as e:
            logging.error("Trappto zabbix error: {} -  {}".format(inspect.stack()[1][3], e))
            return False
    else:
        return False
开发者ID:datapower,项目名称:dpcollector,代码行数:20,代码来源:dpower_tools.py

示例14: ZabbixSink

class ZabbixSink(BaseThreadedModule):
    """
    Send events to zabbix.

    hostname: Hostname for which the metrics should be stored.
    fields: Event fields to send.
    field_prefix: Prefix to prepend to field names. For e.g. cpu_count field with default lumbermill_ prefix, the Zabbix key is lumbermill_cpu_count.
    timestamp_field: Field to provide timestamp. If not provided, current timestamp is used.
    agent_conf: Path to zabbix_agent configuration file. If set to True defaults to /etc/zabbix/zabbix_agentd.conf.
    server: Address of zabbix server. If port differs from default it can be set by appending it, e.g. 127.0.0.1:10052.
    store_interval_in_secs: sending data to es in x seconds intervals.
    batch_size: sending data to es if event count is above, even if store_interval_in_secs is not reached.
    backlog_size: maximum count of events waiting for transmission. Events above count will be dropped.

    Configuration template:

    - ZabbixSink:
       hostname:                        # <type: string; is: required>
       fields:                          # <type: list; is: required>
       field_prefix:                    # <default: "lumbermill_"; type: string; is: optional>
       timestamp_field:                 # <default: "timestamp"; type: string; is: optional>
       agent_conf:                      # <default: True; type: boolean||string; is: optional>
       server:                          # <default: False; type: boolean||string; is: required if agent_conf is False else optional>
       store_interval_in_secs:          # <default: 10; type: integer; is: optional>
       batch_size:                      # <default: 500; type: integer; is: optional>
       backlog_size:                    # <default: 500; type: integer; is: optional>
    """

    module_type = "output"
    """Set module type"""

    def configure(self, configuration):
        BaseThreadedModule.configure(self, configuration)
        self.hostname = self.getConfigurationValue("hostname")
        self.fields = self.getConfigurationValue("fields")
        self.field_prefix = self.getConfigurationValue("field_prefix")
        self.timestamp_field = self.getConfigurationValue("timestamp_field")
        self.batch_size = self.getConfigurationValue('batch_size')
        self.backlog_size = self.getConfigurationValue('backlog_size')
        self.agent_conf = self.getConfigurationValue("agent_conf")
        if self.agent_conf:
            if self.agent_conf is True:
                self.agent_conf = "/etc/zabbix/zabbix_agentd.conf"
            if not os.path.isfile(self.agent_conf):
                self.logger.error("%s does not point to an existing file." % self.agent_conf)
                self.lumbermill.shutDown()
            self.zabbix_sender = ZabbixSender(use_config=self.agent_conf)

        else:
            self.logger.error("asdads")
            server = self.getConfigurationValue("server")
            port = 10051
            if ":" in self.server:
                server, port = self.server.split(":")
            self.zabbix_sender = ZabbixSender(zabbix_server=server, port=port)
        self.buffer = Buffer(self.getConfigurationValue('batch_size'), self.storeData,
                             self.getConfigurationValue('store_interval_in_secs'),
                             maxsize=self.getConfigurationValue('backlog_size'))

    def getStartMessage(self):
        if self.agent_conf:
            return "Config: %s. Max buffer size: %d" % (self.agent_conf, self.getConfigurationValue('backlog_size'))
        else:
            return "Server: %s. Max buffer size: %d" % (self.getConfigurationValue("server"), self.getConfigurationValue('backlog_size'))

    def initAfterFork(self):
        BaseThreadedModule.initAfterFork(self)
        self.buffer = Buffer(self.getConfigurationValue('batch_size'), self.storeData,
                             self.getConfigurationValue('store_interval_in_secs'),
                             maxsize=self.getConfigurationValue('backlog_size'))

    def handleEvent(self, event):
        self.buffer.append(event)
        yield None

    def storeData(self, events):
        packet = []
        for event in events:
            if self.timestamp_field:
                try:
                    timestamp = event[self.timestamp_field]
                except KeyError:
                    timestamp = None
            hostname = mapDynamicValue(self.hostname, mapping_dict=event, use_strftime=True)
            for field_name in self.fields:
                try:
                    packet.append(ZabbixMetric(hostname, "%s%s" % (self.field_prefix, field_name), event[field_name], timestamp))
                except KeyError:
                    pass
                    #self.logger.warning("Could not send metrics for %s:%s. Field not found." % (hostname, field_name))
        response = self.zabbix_sender.send(packet)
        if response.failed != 0:
            self.logger.warning("%d of %d metrics were not processed correctly." % (response.total-response.processed, response.total))

    def shutDown(self):
        self.buffer.flush()
开发者ID:dstore-dbap,项目名称:LumberMill,代码行数:96,代码来源:ZabbixSink.py

示例15: test_load_from_config

 def test_load_from_config(self):
     folder = os.path.dirname(__file__)
     filename = os.path.join(folder, 'data/zabbix_agentd.conf')
     zs = ZabbixSender()
     result = zs._load_from_config(config_file=filename)
     self.assertEqual(result, [('192.168.1.2', 10051)])
开发者ID:0XCFFEC7BF,项目名称:py-zabbix,代码行数:6,代码来源:test_sender.py


注:本文中的pyzabbix.ZabbixSender类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。