def getmysqlcreds():
    """Fetch the mysql creds from the object database and store them
    in the global file for use in later commands.

    returns True on success, False on failure
    """
    pids = os.popen('pgrep -f zeo.py').read().split('\n')
    pids = [int(p) for p in pids if p]
    if len(pids) < 1:
        log.warning('zeo is not running')
        return False
    log.debug("Fetching mysql credentials")
    mysqlpass = '******'
    mysqluser = '******'
    mysqlport = '3306'
    mysqlhost = 'localhost'
    sys.path.insert(0, os.path.join(zenhome, 'lib/python'))
    try:
        import Globals
        from Products.ZenUtils.ZenScriptBase import ZenScriptBase
        zsb = ZenScriptBase(noopts=True, connect=True)
        zsb.getDataRoot()
        dmd = zsb.dmd
        mysqlpass = dmd.ZenEventManager.password
        mysqluser = dmd.ZenEventManager.username
        mysqlport = dmd.ZenEventManager.port
        mysqlhost = dmd.ZenEventManager.host
    except Exception, ex:
        log.exception("Unable to open the object database for "
                      "mysql credentials")
Exemple #2
0
def getmysqlcreds():
    """Fetch the mysql creds from the object database and store them
    in the global file for use in later commands.

    returns True on success, False on failure
    """
    pids = os.popen('pgrep -f zeo.py').read().split('\n')
    pids = [int(p) for p in pids if p]
    if len(pids) < 1:
        log.warning('zeo is not running')
        return False
    log.debug("Fetching mysql credentials")
    print "Fetching mysql credentials"
    mysqlpass = '******'
    mysqluser = '******'
    mysqlport = '3306'
    mysqlhost = 'localhost'
    sys.path.insert(0, os.path.join(zenhome, 'lib/python'))
    try:
        import Globals
        from Products.ZenUtils.ZenScriptBase import ZenScriptBase
        zsb = ZenScriptBase(noopts=True, connect=True)
        zsb.getDataRoot()
        dmd = zsb.dmd
        mysqlpass = dmd.ZenEventManager.password
        mysqluser = dmd.ZenEventManager.username
        mysqlport = dmd.ZenEventManager.port
        mysqlhost = dmd.ZenEventManager.host
    except Exception, ex:
        log.exception("Unable to open the object database for "
                      "mysql credentials")
        pass
Exemple #3
0
def eventStats():
    try:
        import Globals
        from Products.ZenUtils.ZenScriptBase import ZenScriptBase
        from Products.Zuul import getFacade
        zsb = ZenScriptBase(noopts=True, connect=True)
        zsb.getDataRoot()
        zepfacade = getFacade('zep')
        statsList = zepfacade.getStats()
        return '\n\n'.join([str(item) for item in statsList])
    except Exception, ex:
        log = logging.getLogger('zendiag')
        log.exception(ex)
Exemple #4
0
def eventStats():
    try:
        import Globals
        from Products.ZenUtils.ZenScriptBase import ZenScriptBase
        from Products.Zuul import getFacade
        zsb = ZenScriptBase(noopts=True, connect=True)
        zsb.getDataRoot()
        zepfacade = getFacade('zep')
        statsList = zepfacade.getStats()
        return '\n\n'.join([str(item) for item in statsList])
    except Exception, ex:
        log = logging.getLogger('zendiag')
        log.exception(ex)
def zenossInfo():
    "get the About:Versions page data"
    try:
        import Globals
        from Products.ZenUtils.ZenScriptBase import ZenScriptBase
        zsb = ZenScriptBase(noopts=True, connect=True)
        zsb.getDataRoot()
        result = []
        for record in zsb.dmd.About.getAllVersions():
            result.append('%10s: %s' % (record['header'], record['data']))
        result.append('%10s: %s' % ('uuid', zsb.dmd.uuid))
        return '\n'.join(result)
    except Exception, ex:
        log.exception(ex)
Exemple #6
0
def zenossInfo():
    "get the About:Versions page data"

    def format_data(fmt, data):
        return [fmt % datum for datum in data] + ['']

    try:
        print "Gathering info from zodb..."
        import Globals
        from Products.ZenUtils.ZenScriptBase import ZenScriptBase
        from Products.Zuul import getFacade
        zsb = ZenScriptBase(noopts=True, connect=True)
        zsb.getDataRoot()

        header_data = [('Report Data', datetime.datetime.now()),
                       ('Server Key', zsb.dmd.uuid),
                       ('Google Key', zsb.dmd.geomapapikey)]

        counter = {}
        decomm = 0
        for d in zsb.dmd.Devices.getSubDevices():
            if d.productionState < 0:
                decomm += 1
            else:
                index = '%s %s' % \
                    (d.getDeviceClassPath(), d.getProductionStateString())
                count = counter.get(index, 0)
                counter[index] = count + 1

        totaldev = zsb.dmd.Devices.countDevices()

        device_summary_header_data = [
            ('Total Devices', totaldev),
            ('Total Decommissioned Devices', decomm),
            ('Total Monitored Devices', totaldev - decomm),
        ]

        device_summary_header = ['Device Breakdown by Class and State:']

        counter_keylist = counter.keys()
        counter_keylist.sort()
        device_summary_data = [(k, counter[k]) for k in counter_keylist]

        zenpacks_header = ['ZenPacks:']
        zenpack_ids = zsb.dmd.ZenPackManager.packs.objectIds()

        zenoss_versions_data = [(record['header'], record['data'])
                                for record in zsb.dmd.About.getAllVersions()]

        uuid_data = [('uuid', zsb.dmd.uuid)]

        event_start = time.time() - 24 * 60 * 60

        product_count = 0
        for name in zsb.dmd.Manufacturers.getManufacturerNames():
            for product_name in zsb.dmd.Manufacturers.getProductNames(name):
                product_count = product_count + 1

        # Hub collector Data
        collector_header = ['Hub and Collector Information']
        hub_data = []
        remote_count = 0
        local_count = 0
        for hub in zsb.dmd.Monitors.Hub.getHubs():
            hub_data.append("Hub: %s" % hub.id)
            for collector in hub.collectors():
                hub_data.append("\tCollector: %s IsLocal(): %s" %
                                (collector.id, collector.isLocalHost()))
                if not collector.isLocalHost():
                    hub_data.append("\tCollector(Remote): %s" % collector.id)
                    remote_count = remote_count + 1
                else:
                    hub_data.append("\tCollector(Local): %s " % collector.id)
                    local_count = local_count + 1

        zep = getFacade('zep')
        tail_data = [
            ('Evt Rules', zsb.dmd.Events.countInstances()),
            ('Evt Count (Last 24 Hours)', zep.countEventsSince(event_start)),
            ('Reports', zsb.dmd.Reports.countReports()),
            ('Templates', zsb.dmd.Devices.rrdTemplates.countObjects()),
            ('Systems', zsb.dmd.Systems.countChildren()),
            ('Groups', zsb.dmd.Groups.countChildren()),
            ('Locations', zsb.dmd.Locations.countChildren()),
            ('Users', len(zsb.dmd.ZenUsers.getUsers())),
            ('Product Count', product_count),
            ('Local Collector Count', local_count),
            ('Remote Collector Count', remote_count)
        ]

        detail_prefix = '    '
        std_key_data_fmt = '%s: %s'
        detail_std_key_data_fmt = detail_prefix + std_key_data_fmt
        detail_data_fmt = detail_prefix + '%s'
        center_justify_fmt = '%10s: %s'

        return_data = (
            format_data(std_key_data_fmt, header_data) +
            format_data(std_key_data_fmt, device_summary_header_data) +
            device_summary_header +
            format_data(detail_std_key_data_fmt, device_summary_data) +
            zenpacks_header + format_data(detail_data_fmt, zenpack_ids) +
            format_data(center_justify_fmt, zenoss_versions_data + uuid_data) +
            collector_header + format_data('%s', hub_data) +
            format_data(std_key_data_fmt, tail_data))

        return '\n'.join(return_data)

    except Exception, ex:
        log.exception(ex)
def zenossInfo():
    "get the About:Versions page data"

    def format_data(fmt, data):
        return [fmt % datum for datum in data] + ['']

    try:
        print "Gathering info from zodb..."
        import Globals
        from Products.ZenUtils.ZenScriptBase import ZenScriptBase
        from Products.Zuul import getFacade
        zsb = ZenScriptBase(noopts=True, connect=True)
        zsb.getDataRoot()

        header_data = [
            ('Report Data', datetime.datetime.now()),
            ('Server Key', zsb.dmd.uuid),
            ('Google Key', zsb.dmd.geomapapikey)]

        counter = {}
        decomm = 0
        for d in zsb.dmd.Devices.getSubDevices():
            if d.productionState < 0:
                decomm += 1
            else:
                index = '%s %s' % \
                    (d.getDeviceClassPath(), d.getProductionStateString())
                count = counter.get(index, 0)
                counter[index] = count + 1

        totaldev = zsb.dmd.Devices.countDevices()

        device_summary_header_data = [
            ('Total Devices', totaldev),
            ('Total Decommissioned Devices', decomm),
            ('Total Monitored Devices', totaldev - decomm),
        ]

        device_summary_header = ['Device Breakdown by Class and State:']

        counter_keylist = counter.keys()
        counter_keylist.sort()
        device_summary_data = [(k, counter[k]) for k in counter_keylist]

        zenpacks_header = ['ZenPacks:']
        zenpack_ids = zsb.dmd.ZenPackManager.packs.objectIds()

        zenoss_versions_data = [
            (record['header'], record['data']) for
                record in zsb.dmd.About.getAllVersions()]

        uuid_data = [('uuid', zsb.dmd.uuid)]

        event_start = time.time() - 24 * 60 * 60

        product_count=0
        for name in zsb.dmd.Manufacturers.getManufacturerNames():
            for product_name in zsb.dmd.Manufacturers.getProductNames(name):
                product_count = product_count + 1 

        # Hub collector Data
        collector_header = ['Hub and Collector Information']
        hub_data = []
        remote_count = 0
        local_count = 0 
        for hub in zsb.dmd.Monitors.Hub.getHubs():
            hub_data.append("Hub: %s" % hub.id)
            for collector in hub.collectors():
                    hub_data.append("\tCollector: %s IsLocal(): %s" % (collector.id,collector.isLocalHost()))
                    if not collector.isLocalHost():
                        hub_data.append("\tCollector(Remote): %s" % collector.id)
                        remote_count = remote_count + 1
                    else:
                        hub_data.append("\tCollector(Local): %s " % collector.id)
                        local_count = local_count + 1

        zep = getFacade('zep')
        tail_data = [
            ('Evt Rules', zsb.dmd.Events.countInstances()),
            ('Evt Count (Last 24 Hours)', zep.countEventsSince(event_start)),
            ('Reports', zsb.dmd.Reports.countReports()),
            ('Templates', zsb.dmd.Devices.rrdTemplates.countObjects()),
            ('Systems', zsb.dmd.Systems.countChildren()),
            ('Groups', zsb.dmd.Groups.countChildren()),
            ('Locations', zsb.dmd.Locations.countChildren()),
            ('Users', len(zsb.dmd.ZenUsers.getUsers())),
            ('Product Count', product_count),
            ('Local Collector Count', local_count),
            ('Remote Collector Count', remote_count)]

        detail_prefix = '    '
        std_key_data_fmt = '%s: %s'
        detail_std_key_data_fmt = detail_prefix + std_key_data_fmt
        detail_data_fmt = detail_prefix + '%s'
        center_justify_fmt = '%10s: %s'

        return_data = (
            format_data(std_key_data_fmt, header_data) +
            format_data(std_key_data_fmt, device_summary_header_data) +
            device_summary_header +
            format_data(detail_std_key_data_fmt, device_summary_data) +
            zenpacks_header +
            format_data(detail_data_fmt, zenpack_ids) +
            format_data(center_justify_fmt, zenoss_versions_data + uuid_data) +
            collector_header +
            format_data('%s', hub_data) +
            format_data(std_key_data_fmt, tail_data))

        return '\n'.join(return_data)

    except Exception, ex:
        log.exception(ex)