How to use pyzabbix - 10 common examples

To help you get started, we’ve selected a few pyzabbix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adubkov / py-zabbix / tests / test_sender.py View on Github external
def test_init(self):
        zs = ZabbixSender()
        self.assertEqual(zs.__class__.__name__, 'ZabbixSender')
        self.assertEqual(isinstance(zs.zabbix_uri[0], tuple), True)
        self.assertEqual(zs.zabbix_uri[0][0], '127.0.0.1')
        self.assertEqual(zs.zabbix_uri[0][1], 10051)
github adubkov / py-zabbix / tests / test_sender.py View on Github external
def test_init(self):
        zr = ZabbixResponse()
        self.assertEqual(zr.failed, 0)
        self.assertEqual(zr.processed, 0)
        self.assertEqual(zr.time, 0)
        self.assertEqual(zr.total, 0)
        self.assertEqual(zr.chunk, 0)
github lukecyca / pyzabbix / tests / test_api.py View on Github external
def test_host_get(self):
        httpretty.register_uri(
            httpretty.POST,
            "http://example.com/api_jsonrpc.php",
            body=json.dumps({
                "jsonrpc": "2.0",
                "result": [{"hostid": 1234}],
                "id": 0
            }),
        )

        zapi = ZabbixAPI('http://example.com')
        zapi.auth = "123"
        result = zapi.host.get()

        # Check request
        self.assertEqual(
            json.loads(httpretty.last_request().body.decode('utf-8')),
            {
                'jsonrpc': '2.0',
                'method': 'host.get',
                'params': {},
                'auth': '123',
                'id': 0,
            }
        )

        # Check response
github adubkov / py-zabbix / tests / test_sender.py View on Github external
def test_repr(self):
        zm = ZabbixMetric('host1', 'key1', 100500)
        zm_repr = json.loads(zm.__repr__())
        self.assertEqual(zm_repr, zm.__dict__)
github StackStorm-Exchange / stackstorm-zabbix / tests / test_maintenance_create_or_update.py View on Github external
def test_run_maintenance_error(self, mock_connect):
        action = self.get_action_instance(self.full_config)
        mock_connect.return_vaue = "connect return"
        test_dict = {'host': "test",
                    'time_type': 0,
                    'maintenance_window_name': "test",
                    'maintenance_type': 0,
                    'start_date': "2017-11-14 10:40",
                    'end_date': "2017-11-14 10:45"}
        host_dict = {'name': "test", 'hostid': '1'}
        maintenance_dict = {'maintenanceids': ['1']}
        action.connect = mock_connect
        action.find_host = mock.MagicMock(return_value=host_dict['hostid'])
        action.maintenance_create_or_update = mock.MagicMock(return_value=maintenance_dict,
            side_effect=ZabbixAPIException('maintenance error'))

        with self.assertRaises(ZabbixAPIException):
            action.run(**test_dict)
github StackStorm-Exchange / stackstorm-zabbix / tests / test_host_get_multiple_ids.py View on Github external
def test_run_host_error(self, mock_connect):
        action = self.get_action_instance(self.full_config)
        mock_connect.return_vaue = "connect return"
        test_dict = {'host': "test"}
        host_dict = {'name': "test", 'hostid': '1'}
        action.find_hosts = mock.MagicMock(return_value=host_dict['hostid'],
            side_effect=ZabbixAPIException('host error'))
        action.connect = mock_connect
        with self.assertRaises(ZabbixAPIException):
            action.run(**test_dict)
github StackStorm-Exchange / stackstorm-zabbix / tests / test_maintenance_delete.py View on Github external
def test_run_delete_error(self, mock_connect, mock_client):
        action = self.get_action_instance(self.full_config)
        mock_connect.return_vaue = "connect return"
        test_dict = {'maintenance_window_name': None, 'maintenance_id': '1'}
        action.connect = mock_connect
        mock_client.maintenance.delete.side_effect = ZabbixAPIException('maintenance error')
        mock_client.maintenance.delete.return_value = "delete return"
        action.client = mock_client

        with self.assertRaises(ZabbixAPIException):
            action.run(**test_dict)
github StackStorm-Exchange / stackstorm-zabbix / tests / test_host_delete.py View on Github external
def test_run_delete_error(self, mock_connect, mock_client):
        action = self.get_action_instance(self.full_config)
        mock_connect.return_vaue = "connect return"
        test_dict = {'host': "test"}
        host_dict = {'name': "test", 'hostid': '1'}
        action.connect = mock_connect
        action.find_host = mock.MagicMock(return_value=host_dict['hostid'])
        mock_client.host.delete.side_effect = ZabbixAPIException('host error')
        mock_client.host.delete.return_value = "delete return"
        action.client = mock_client

        with self.assertRaises(ZabbixAPIException):
            action.run(**test_dict)
github StackStorm-Exchange / stackstorm-zabbix / tests / test_action_base.py View on Github external
def test_find_host_fail(self, mock_client):
        action = self.get_action_instance(self.full_config)
        test_dict = {'host_name': "test", 'hostid': "1"}
        mock_client.host.get.side_effect = ZabbixAPIException('host error')
        mock_client.host.get.return_value = [test_dict]
        action.client = mock_client

        with self.assertRaises(ZabbixAPIException):
            action.find_host(test_dict['host_name'])
github StackStorm-Exchange / stackstorm-zabbix / tests / test_host_get_status.py View on Github external
def test_run_host_error(self, mock_connect):
        action = self.get_action_instance(self.full_config)
        mock_connect.return_vaue = "connect return"
        test_dict = {'host': "test"}
        host_dict = {'name': "test", 'hostid': '1'}
        action.find_host = mock.MagicMock(return_value=host_dict['hostid'],
            side_effect=ZabbixAPIException('host error'))
        action.connect = mock_connect
        with self.assertRaises(ZabbixAPIException):
            action.run(**test_dict)