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


Python ZabbixSender.send方法代码示例

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


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

示例1: test_send_sendall_exception

# 需要导入模块: from pyzabbix import ZabbixSender [as 别名]
# 或者: from pyzabbix.ZabbixSender import send [as 别名]
    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,代码行数:10,代码来源:test_sender.py

示例2: test_send_failed

# 需要导入模块: from pyzabbix import ZabbixSender [as 别名]
# 或者: from pyzabbix.ZabbixSender import send [as 别名]
    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,代码行数:14,代码来源:test_sender.py

示例3: test_send

# 需要导入模块: from pyzabbix import ZabbixSender [as 别名]
# 或者: from pyzabbix.ZabbixSender import send [as 别名]
    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,代码行数:11,代码来源:test_sender.py

示例4: test_send

# 需要导入模块: from pyzabbix import ZabbixSender [as 别名]
# 或者: from pyzabbix.ZabbixSender import send [as 别名]
    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,代码行数:14,代码来源:test_sender.py

示例5: trapper

# 需要导入模块: from pyzabbix import ZabbixSender [as 别名]
# 或者: from pyzabbix.ZabbixSender import send [as 别名]
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,代码行数:22,代码来源:dpower_tools.py

示例6: ZabbixSink

# 需要导入模块: from pyzabbix import ZabbixSender [as 别名]
# 或者: from pyzabbix.ZabbixSender import send [as 别名]
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,代码行数:98,代码来源:ZabbixSink.py

示例7: on_message

# 需要导入模块: from pyzabbix import ZabbixSender [as 别名]
# 或者: from pyzabbix.ZabbixSender import send [as 别名]
def on_message(client, userdata, msg):
    packet = [
      ZabbixMetric(zabbix_item_host, zabbix_item_name, str(msg.payload)),
    ]
    sender = ZabbixSender(zabbix_server=zabbix_host, zabbix_port=10051, use_config=None)
    sender.send(packet)
开发者ID:fxpester,项目名称:mqtt_to_zabbix,代码行数:8,代码来源:mqtt_to_zabbix.py


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