Beispiel #1
0
class TestZenoss(unittest.TestCase):
    def setUp(self):
        self.api = Zenoss('http://zenoss:8080', 'admin', 'password')

    def test_get_devices(self):
        with HTTMock(response_content):
            result = self.api.get_devices()
            self.assertTrue(result['success'])

    def test_get_events(self):
        with HTTMock(response_content):
            result = self.api.get_events()
            self.assertTrue(type(result is list))
            self.assertTrue('count' in result[0])

    def test_add_device(self):
        with HTTMock(response_content):
            result = self.api.add_device(TEST_SERVERNAME,
                                         '/Devices/Server/Linux')
            self.assertTrue(result['success'])

    def test_remove_device(self):
        with HTTMock(response_content):
            result = self.api.remove_device(TEST_SERVERNAME)
            self.assertTrue(result['success'])

    def test_create_event_on_device(self):
        with HTTMock(response_content):
            self.api.create_event_on_device(TEST_SERVERNAME, 'Error',
                                            'This is just an error')

    def test_ack_event(self):
        with HTTMock(response_content):
            events = self.api.get_events()
            if len(events) > 0:
                self.assertTrue(
                    self.api.ack_event(events[0]['evid'])['success'])

    def test_close_event(self):
        with HTTMock(response_content):
            events = self.api.get_events()
            if len(events) > 0:
                self.assertTrue(
                    self.api.close_event(events[0]['evid'])['success'])
class TestZenoss(unittest.TestCase):
    def setUp(self):
        self.api = Zenoss('http://zenoss:8080', 'admin', 'password')

    def test_get_devices(self):
        with HTTMock(response_content):
            result = self.api.get_devices()
            self.assertTrue(result['success'])

    def test_get_events(self):
        with HTTMock(response_content):
            result = self.api.get_events()
            self.assertTrue(type(result is list))
            self.assertTrue('count' in result[0])

    def test_add_device(self):
        with HTTMock(response_content):
            result = self.api.add_device(TEST_SERVERNAME, '/Devices/Server/Linux')
            self.assertTrue(result['success'])

    def test_remove_device(self):
        with HTTMock(response_content):
            result = self.api.remove_device(TEST_SERVERNAME)
            self.assertTrue(result['success'])

    def test_create_event_on_device(self):
        with HTTMock(response_content):
            self.api.create_event_on_device(TEST_SERVERNAME, 'Error', 'This is just an error')

    def test_ack_event(self):
        with HTTMock(response_content):
            events = self.api.get_events()
            if len(events) > 0:
                self.assertTrue(self.api.ack_event(events[0]['evid'])['success'])

    def test_close_event(self):
        with HTTMock(response_content):
            events = self.api.get_events()
            if len(events) > 0:
                self.assertTrue(self.api.close_event(events[0]['evid'])['success'])
Beispiel #3
0
#!/usr/local/env python

from zenoss import Zenoss, EventState, EventSeverity
import json

# create Zenoss instance
zenoss = Zenoss(host='https://zenoss.host.com',
                cert='/path/to/cert.pem',
                ssl_verify=False)

# get events
params = dict(eventState=[EventState.new],
              severity=[EventSeverity.critical],
              Systems='/ReleaseEnvironment/Live')
events = zenoss.get_events(limit=1,
                           sort='firstTime',
                           dir='ASC',
                           params=params,
                           detailFormat=False)

# display JSON
print json.dumps(events, indent=2)
#!/usr/local/env python

from zenoss import Zenoss, EventState, EventSeverity
import json

# create Zenoss instance
zenoss = Zenoss(
            host = 'https://zenoss.host.com',
            cert = '/path/to/cert.pem',
            ssl_verify = False
            )

# get events
params = dict(
        eventState = [EventState.new],
        severity = [EventSeverity.critical],
        Systems = '/ReleaseEnvironment/Live'
        )
events = zenoss.get_events(limit=1, sort='firstTime', dir='ASC', params=params, detailFormat=False)

# display JSON
print json.dumps(events, indent=2)