def test_login(self):
        httpretty.register_uri(
            httpretty.POST,
            "http://java.zabbix.dooioo.com/api_jsonrpc.php",
            body=json.dumps({
                "jsonrpc": "2.0",
                "result": "0424bd59b807674191e7d77572075f33",
                "id": 0
            }),
        )

        zapi = ZabbixClient()
        zapi.login_in()
        # Check request
        self.assertEqual(
            json.loads(httpretty.last_request().body.decode('utf-8')),
            {
                'jsonrpc': '2.0',
                'method': 'user.login',
                'params': {'user': '******', 'password': '******'},
                'id': 0,
                'auth': ''
            }
        )
        self.assertEqual(
            httpretty.last_request().headers['content-type'],
            'application/json-rpc'
        )
        self.assertEqual(
            httpretty.last_request().headers['user-agent'],
            'python-zabbix-client'
        )

        # Check response
        self.assertEqual(zapi.auth, "0424bd59b807674191e7d77572075f33")
 def test_get_item(self):
     zapi = ZabbixClient()
     zapi.login_in()
     templates = zapi.template.get()
     print(templates)
     for item in templates:
         print(item['name'])
         for k, v in item.items():
             print(k, v)
     self.assertIsNotNone(templates)
class TestZabbixTemplateClient(unittest.TestCase):
    def setUp(self):
        self.zapi = ZabbixClient()
        self.zapi.login_in()

    def test_create_host_group(self):
        host_group = self.zapi.hostgroup.create(
            name='TEST_TEMPLATE_GROUP'
        )
        print(host_group['groupids'][0])

    def test_delete_host_group(self):
        host_group = self.zapi.hostgroup.delete('36')
        print(host_group)
class TestZabbixTemplateClient(unittest.TestCase):

    def setUp(self):
        self.zapi = ZabbixClient()
        self.zapi.login_in()

    def test_get_template(self):
        templates = self.zapi.template.get()
        print(templates)

    def test_get_template(self):
        templates = self.zapi.template.get(
            filter={
                "host": ["Template OS Linux"]
            })
        print(templates[0]["id"])

    def test_create_template(self):
        template = self.zapi.template.create()
 def setUp(self):
     self.zapi = ZabbixClient()
     self.zapi.login_in()
 def test_get_host(self):
     zapi = ZabbixClient()
     zapi.login_in()
     hosts = zapi.host.get()
     self.assertIsNotNone(hosts)
예제 #7
0
 def setUp(self):
     monitor_description = MonitorDescription(ip='10.0.0.1')
     self.z_client = ZabbixClient(monitor_description)
예제 #8
0
class TestZabbixClient(TestCase):
    def setUp(self):
        monitor_description = MonitorDescription(ip='10.0.0.1')
        self.z_client = ZabbixClient(monitor_description)

    def test_login(self):
        self.z_client.login()
        logger.debug(self.z_client.auth)
        self.assertIsNotNone(self.z_client.auth)

    def test_api_info(self):
        api_info = self.z_client.api_version()
        logger.debug(api_info)
        self.assertIsNotNone(api_info)

    def test_get_existing_host_group_name(self):
        self.z_client.login()
        host_group_names = self.z_client.get_exiting_host_group_ids()
        self.assertEqual(host_group_names[0]['name'], 'JMX')

    def test_get_multiple_existing_host_group_name(self):
        self.z_client.login()
        self.z_client.monitor_description.host_group_names.append('Solr')
        host_group_ids = self.z_client.get_exiting_host_group_ids()
        self.assertEqual(host_group_ids, [{"groupid": '8'}, {"groupid": '9'}])

    def test_get_existing_templates(self):
        self.z_client.login()
        templates = self.z_client.get_existing_templates()
        self.assertEqual(templates[0]['host'], 'Template JMX Generic')

    def test_get_multiple_templates(self):
        self.z_client.monitor_description = MonitorDescription(
            ip='10.0.0.1',
            monitor_template_names=['Template App IMAP Service'])
        self.z_client.login()
        templates = self.z_client.get_existing_templates()
        self.assertEqual(templates[1]['host'], 'Template JMX Generic')
        self.assertEqual(templates[0]['host'], 'Template App IMAP Service')

    def test_create_new_monitor_for_host(self):
        self.z_client.monitor_description = MonitorDescription(
            ip='10.22.16.136')
        self.z_client.create_monitor()

    def test_get_trigger_info():
        self.z_client.login()
        triggers = self.z_client.trigger.get()