示例#1
0
def connection_setup(host):
    logger.info('Connecting to: {}'.format(host))
    return Zenoss(host=('%s' % host),
                  username=connect_params['username'],
                  password=connect_params['password'],
                  cert=connect_params['cert'],
                  ssl_verify=connect_params['ssl_verify'])
示例#2
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'])
示例#3
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'])
示例#4
0

if __name__ == "__main__":
    import datetime
    start_time = datetime.datetime.now()

    load_properties()
    if not connect_params['enabled']:
        sys.exit(0)

    logger.info('------------------- starting -------------------------')
    try:
        test_mode = connect_params['test_mode']
        zenoss_src = connection_setup(host=connect_params['src_host'])
        src_devices = build_device_data_structure(
            Zenoss.get_devices(zenoss_src))

        zenoss_dest = connection_setup(host=connect_params['dest_host'])
        dest_devices = build_device_data_structure(
            Zenoss.get_devices(zenoss_dest))

        src_unique_devices, dest_unique_devices = find_unique_devices(
            src_devices, dest_devices)

        # now remove systems to be ignore
        remove_ignored_devices(src_unique_devices, devices_to_ignore)
        remove_ignored_devices(dest_unique_devices, devices_to_ignore)

        src_collector_totals = find_collector_device_totals(src_devices)
        dest_collector_totals = find_collector_device_totals(dest_devices)
#!/usr/bin/env python

from zenoss import Zenoss

zenoss = Zenoss('http://zenoss:8080/', 'admin', 'password')

for device in zenoss.get_devices()['devices']:
    print(device['name'])

示例#6
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/bin/env python
__author__ = '*****@*****.**'
from zenoss import Zenoss
import json
import argparse
from ConfigParser import SafeConfigParser

# get zenoss url/user/pass from config.ini file in local directory
parser = SafeConfigParser()
parser.read('config.ini')
uri = parser.get('zenoss', 'uri')
username = parser.get('zenoss', 'username')
password = parser.get('zenoss', 'password')

# create connection and zenoss obj
zenoss = Zenoss(uri, username, password)


class ZenossInventory(object):
    def __init__(self):
        self.inventory = {}
        self.read_cli_args()

        if self.args.list:
            self.inventory = self.get_inventory()
        else:
            # return nothing if --list isn't specified
            self.inventory = self.empty_inventory()

        print json.dumps(self.inventory)
示例#8
0
 def setUp(self):
     self.api = Zenoss('http://zenoss:8080', 'admin', 'password')
示例#9
0
from zenoss import Zenoss
import json

rm = Zenoss(
    'http://your.rm.instance.loc/',
    username='******',
    password='******',
    #cert='/path/to/your.cert.pem',
    ssl_verify=False)

device_list = ['10.160.32.{}'.format(i) for i in range(1, 100)]

for dev_name in device_list:

    #out = rm.remove_device(
    #    device_name=dev_name,
    #)

    out = rm.add_device(device_name=dev_name,
                        device_class='/Server/Linux',
                        model=True,
                        manageIp=dev_name)
    print(out)
示例#10
0
 def setUp(self):
     self.api = Zenoss('http://zenoss:8080', 'admin', 'password')
cfg.read('/opt/smokeping2zenoss/zensmokeping.cfg')

#Clear detection
#TODO: Severity value should come from Smokeping alert to Zenoss severity mapping
clear = alert.find(CLEARSTR.title())
if clear >= 0:
    alert = alert[0:-len(CLEARSTR)]
    severity = "Clear"
else:
###    severity = "Critical"
    if (cfg.has_section(alert)):
###        print "Severity should be", cfg.get(alert, 'severity')
        severity = cfg.get(alert, 'severity')

event = ""
if alert == "Lossdetector":
    event = losspercent + " packet loss detected to "
elif alert == "Rttdetector":
    event = rttave + " RTT detected to "

summary = event
summary += device + " " + loss + " "
summary += rtt

evdata = {'device': device, 'summary': summary, 'severity': severity, 'component': alert, 'evclass': "/Status/Smokeping", 'evclasskey': 'smokeping' }

#z = Zenoss('https://zenoss_ip', 'smokeping', 'password')
z = Zenoss('http://zenoss-smokeping.cascadeo.com:8080', 'admin', 'z3n0ss99')
z.create_event_on_device(evdata)
logging.info("Pushed event to Zenoss")
示例#12
0
def get_zenoss(config):
    host = config.get('zenoss', 'host')
    port = config.getint('zenoss', 'port')
    user = config.get('zenoss', 'user')
    password = config.get('zenoss', 'password')
    return Zenoss('http://%s:%s/' % (host, port), user, password)
#!/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)