def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option("-z", "--zenpack", dest="zenpack", help="ZenPack to Add Templates To", metavar="ZenPack")
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option("-f", "--file", dest="filename", help="write json to FILE", metavar="FILE") self.parser.add_option("-z", "--zenpack", dest="zenpack", help="ZenPack to Dump Templates From", metavar="ZenPack")
def processResults(self, cmd, result): """ Process the results for command "lsdrive -delim :". """ update = False datapointMap = dict([(dp.id, dp) for dp in cmd.points]) devname = cmd.deviceConfig.device # returned from datasource component field with ${here/id} componentid = cmd.component rresult = Utils.cmdParser(cmd.result.output,'id','DRIVE_ID') # specific component device rresult = rresult[componentid] # drive status raise event if rresult['status']!='online': result.events.append(Utils.getEvent(cmd,"Drive status not online",clear=False)) update = True # drive error sequence number if rresult['error_sequence_number']!='': result.events.append(Utils.getEvent(cmd,"Drive error sequence number: "+rresult['error_sequence_number'],clear=False)) update = True # update current component if needed if update: scriptbase = ZenScriptBase(noopts = 1, connect = True) device = scriptbase.findDevice(devname) component = device.drives.findObjectsById(componentid)[0] component.drive_status=rresult['status'] component.error_sequence_number=rresult['error_sequence_number'] commit()
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option('--collector', dest='collectorId', default='localhost', metavar='COLLECTOR_ID', help="Name of specific collector on which to run the command") self.parser.add_option('--timeout', dest='timeout', default=60, type="int", help="Kill the process after this many seconds.")
def __init__(self): """ create object and and coonect to the db """ ZenScriptBase.__init__(self, connect=True) self.log = logging.getLogger("EventModder") self.api = getFacade("event")
def buildOptions(self): self.parser.add_option('--step', action='append', dest="steps", help="Run the specified step. This option " 'can be specified multiple times to run ' 'more than one step.') # NB: The flag for this setting indicates a false value for the setting. self.parser.add_option('--dont-commit', dest="commit", action='store_false', default=True, help="Don't commit changes to the database") self.parser.add_option('--list', action='store_true', default=False, dest="list", help="List all the steps") self.parser.add_option('--level', dest="level", type='string', default=None, help="Run the steps for the specified level " ' and above.') self.parser.add_option('--newer', dest='newer', action='store_true', default=False, help='Only run steps with versions higher ' 'than the current database version.' 'Usually if there are no newer ' 'migrate steps the current steps ' 'are rerun.') ZenScriptBase.buildOptions(self)
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option( "--age", dest="age", type="int", default=1, help="Number of days old to consider fresh (default=1)" ) self.parser.add_option( "--all", dest="all", action="store_true", default=False, help="Check all data points. Not just ones used in graphs", ) self.parser.add_option( "--pathcache", dest="pathcache", action="store_true", default=False, help="Cache the full list of RRD file paths in the model", ) self.parser.add_option( "--devicesonly", dest="devicesonly", action="store_true", default=False, help="Only check for device files. Not components", ) self.parser.add_option("--collector", dest="collector", help="Name of specific collector to check (optional)") self.parser.add_option("-o", "--file", dest="file", help="Output filename") self.parser.add_option( "--sendevent", dest="sendevent", action="store_true", default=False, help="Send an event with statistics per collector", )
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")
def __init__(self, connect=False): ZenScriptBase.__init__(self) if connect is True: self.connect() self.status = 0 self.message = "" self.exitStatusMap = {"OK": 0, "WARNING": 1, "CRITICAL": 2}
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option('--url', '-u', dest='url', default=None, help='URL of report to send') self.parser.add_option('--reportFileType', '-r', dest='reportFileType', default='PDF', help='report file type (%s)' % "|".join(gValidReportFileTypes)) self.parser.add_option('--user', '-U', dest='user', default='admin', help="User to log into Zenoss") self.parser.add_option('--passwd', '-p', dest='passwd', help="Password to log into Zenoss") self.parser.add_option('--address', '-a', dest='addresses', default=[], action='append', help='Email address destination ' '(may be given more than once). Default value' "comes from the user's profile.") self.parser.add_option('--subject', '-s', dest='subject', default='', help='Subject line for email message.' 'Default value is the title of the html page.') self.parser.add_option('--from', '-f', dest='fromAddress', default='zenoss@localhost', help='Origination address')
def buildOptions(self): """basic options setup sub classes can add more options here""" ZenScriptBase.buildOptions(self) self.parser.add_option('-M', '--master', dest='master', default=False, action='store_true', help='Gather zenoss master data') self.parser.add_option('-p', dest='pretty', default=False, action='store_true', help='pretty print the output') self.parser.add_option('-i', '--json_indent', dest='jsonIndent', help='indent setting for json output', default=None, type='int') self.parser.add_option('-s', '--status', action='store_true', dest='status', help='show detail status information', default=False)
def buildOptions(self): """ add some additional options """ ZenScriptBase.buildOptions(self) self.parser.add_option('--mode', dest="mode", default=None, help="Specify operating mode:\neval = evaluate an existing "\ "threshold against a specific device\ntest = create a " \ "test threshold and evaluate it against a device") self.parser.add_option('--device', "-d", dest="device", type="str", default=None, help="Specfiy a device for threshold evaluation (eval & test mode)") self.parser.add_option('--template_path', '-p', type="str", dest="tpath", default=None, help="Specify the path to a template path i.e. /zport/dmd/Devices/rrdTemplates/Device (eval mode)") self.parser.add_option('--min', '-i', type="str", dest="min", default=None, help="Specify a minimum value to be used for the threshold (eval mode)") self.parser.add_option('--max', '-a', type="str", dest="max", default=None, help="Specify a maximum value to be used for the threshold (eval mode)") self.parser.add_option('--value', type="str", dest="value", default=None, help="Specify an artificial value to use for threshold evaluation (eval mode)")
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
def buildOptions(self): self.parser.add_option( '--list', dest='list', default=False, action='store_true', help='List the names of ZenPack-supplied daemons') ZenScriptBase.buildOptions(self)
def __init__(self): ZenScriptBase.__init__(self, connect=True) self.profiles = self.dmd.Profiles self.rulesets = self.profiles.getAllRulesets() self.rulesetfile = 'profiles-rulesets-export.txt' self.rulefile = 'profiles-rules-export.txt' self.exportrulesets = [] self.exportrules = []
def buildOptions(self): self.parser.add_option('--list', dest='list', default=False, action='store_true', help='List the names of ZenPack-supplied daemons' ) ZenScriptBase.buildOptions(self)
def buildOptions(self): self.parser.add_option('--install', dest='installPackName', default=None, help="Path to the ZenPack to install.") self.parser.add_option('--fetch', dest='fetch', default=None, help='Name of ZenPack to retrieve from ' 'Zenoss and install.') self.parser.add_option('--remove', '--delete', '--uninstall', '--erase', dest='removePackName', default=None, help="Name of the ZenPack to remove.") self.parser.add_option('--list', dest='list', action="store_true", default=False, help='List installed ZenPacks') self.parser.add_option('--link', dest='link', action="store_true", default=False, help="Install the ZenPack in place, without " "copying into $ZENHOME/ZenPacks.") self.parser.add_option('--files-only', dest='filesOnly', action="store_true", default=False, help='Install the ZenPack files onto the ' 'filesystem, but do not install the ' 'ZenPack into Zenoss.') self.parser.add_option('--fromui', dest='fromui', action="store_true", default=False, help=optparse.SUPPRESS_HELP) self.parser.add_option('--previousversion', dest='previousVersion', default=None, help="Previous version of the zenpack;" ' used during upgrades') self.parser.add_option('--if-installed', action="store_true", dest='ifinstalled', default=False, help="Delete ZenPack only if installed") self.parser.add_option( '--skip-same-version', action="store_true", dest='skipSameVersion', default=False, help="Do not install the zenpack if the version is unchanged") self.parser.prog = "zenpack" ZenScriptBase.buildOptions(self)
def buildOptions(self): self.parser.add_option('--newid', dest='newid', default=None, help='Specify a new name for this ZenPack. ' 'It must contain at least three package names ' 'separated by periods, the first one being ' '"ZenPacks"') ZenScriptBase.buildOptions(self)
def parseOptions(self): ZenScriptBase.parseOptions(self) if not self.options.filename: print "Required option output file is missing. Exiting..." sys.exit(1) if not self.options.zenpack: print "Required option source zenpack is missing. Exiting..." sys.exit(1)
def buildOptions(self): self.parser.add_option('--devid', dest='devid', default=None, help="device ip or id") self.parser.add_option('--action', dest='action', default=None, help="exec action") ZenScriptBase.buildOptions(self)
def buildOptions(self): """ """ ZenScriptBase.buildOptions(self) self.parser.add_option('--name', dest='name', help='Friendly name for test') self.parser.add_option('--url', dest='url', help='URL for Twill script') self.parser.add_option('--script', dest='script', help='script contents')
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option('--collector', dest='collector', help="Name of specific collector on which to run the command") self.parser.add_option('--timeout', dest='timeout', default=60, type="int", help="Kill the process after this many seconds.") self.parser.add_option('-n', '--useprefix', action='store_false', dest='useprefix', default=True, help="Prefix the collector name for remote servers")
def buildOptions(self): """build script specific options""" ZenScriptBase.buildOptions(self) # call baseclasses's buildOptions self.parser.add_option( '--tempdb-host', dest="tempdb_host", default=None, help= "host for temporary database, uses current zodb host if not specified" ) self.parser.add_option( '--tempdb-port', dest="tempdb_port", default=None, help= "port for temporary database, uses current zodb port if not specified" ) self.parser.add_option( '--tempdb-socket', dest="tempdb_socket", default=None, help= "unix socket for temporary database, uses current zodb socket if not specified" ) self.parser.add_option( '--tempdb-user', dest="tempdb_user", default='root', help="user for temporary database, uses 'root' if not specified") self.parser.add_option('--tempdb-passwd', dest="tempdb_passwd", default=None, help="password for temporary database") self.parser.add_option('--tempdb-name', dest="tempdb_name", default='zodb_temp', help="name for temporary database") self.parser.add_option('--zodb-backup-path', dest="zodb_backup_path", default='/tmp', help="backup path for current zodb") self.parser.add_option('--dry-run', dest="dryRun", default=False, action='store_true', help="don't actually perform any actions")
def main(): """ Scans through zodb hierarchy (from user-supplied path, defaults to /, checking for PKEs """ execution_start = time.time() cli_options = parse_options() log = configure_logging('findposkeyerror') log.info("Command line options: %s" % (cli_options)) if cli_options['debug']: log.setLevel(logging.DEBUG) # Attempt to get the zenoss.toolbox lock before any actions performed if not get_lock("zenoss.toolbox", log): sys.exit(1) # Obtain dmd ZenScriptBase connection dmd = ZenScriptBase(noopts=True, connect=True).dmd log.debug("ZenScriptBase connection obtained") counters = { 'item_count': Counter(0), 'error_count': Counter(0), 'repair_count': Counter(0) } processed_path = re.split("[./]", cli_options['path']) if processed_path[0] == "app": processed_path = processed_path[1:] processed_path = '/'.join(processed_path) if processed_path else '/' try: folder = dmd.getObjByPath(processed_path) except KeyError: print "Invalid path: %s" % (cli_options['path']) else: print("[%s] Examining items under the '%s' path (%s):\n" % (strftime( "%Y-%m-%d %H:%M:%S", localtime()), cli_options['path'], folder)) log.info("Examining items under the '%s' path (%s)" % (cli_options['path'], folder)) findPOSKeyErrors(folder, cli_options['fix'], cli_options['unlimitedram'], dmd, log, counters) print print("\n[%s] Execution finished in %s\n" % (strftime("%Y-%m-%d %H:%M:%S", localtime()), datetime.timedelta(seconds=int(time.time() - execution_start)))) log.info("findposkeyerror completed in %1.2f seconds" % (time.time() - execution_start)) log.info("############################################################") if ((counters['error_count'].value() > 0) and not cli_options['fix']): print("** WARNING ** Issues were detected - Consult KB article at") print(" https://support.zenoss.com/hc/en-us/articles/203117795\n") sys.exit(1) else: sys.exit(0)
def buildOptions(self): self.parser.add_option('--install', dest='installPackName', default=None, help="Path to the ZenPack to install.") self.parser.add_option('--fetch', dest='fetch', default=None, help='Name of ZenPack to retrieve from ' 'Zenoss and install.') self.parser.add_option('--remove', '--delete', '--uninstall', '--erase', dest='removePackName', default=None, help="Name of the ZenPack to remove.") self.parser.add_option('--list', dest='list', action="store_true", default=False, help='List installed ZenPacks') self.parser.add_option('--link', dest='link', action="store_true", default=False, help="Install the ZenPack in place, without " "copying into $ZENHOME/ZenPacks.") self.parser.add_option('--files-only', dest='filesOnly', action="store_true", default=False, help='Install the ZenPack files onto the ' 'filesystem, but do not install the ' 'ZenPack into Zenoss.') self.parser.add_option('--fromui', dest='fromui', action="store_true", default=False, help=optparse.SUPPRESS_HELP) self.parser.add_option('--previousversion', dest='previousVersion', default=None, help="Previous version of the zenpack;" ' used during upgrades') self.parser.add_option('--if-installed', action="store_true", dest='ifinstalled', default=False, help="Delete ZenPack only if installed") self.parser.add_option('--skip-same-version', action="store_true", dest='skipSameVersion', default=False, help="Do not install the zenpack if the version is unchanged") self.parser.prog = "zenpack" ZenScriptBase.buildOptions(self)
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option('-d', '--device', dest="device", help="Device on which to test command") self.parser.add_option('--datasource', dest="dsName", help="COMMAND datasource to test") self.parser.add_option('-t', '--timeout', dest="timeout", default=1, type="int", help="Command timeout")
def __init__(self): """ create object and and connect to the db """ ZenScriptBase.__init__(self, connect=True) self.log = logging.getLogger("TS") self.mode = self.options.mode self.device = self.options.device self.template = self.options.tpath self.min = self.options.min self.max = self.options.max self.value = self.options.value
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option("-f", "--file", dest="filename", help="write objects to FILE", metavar="FILE") self.parser.add_option("-z", "--zenpack", dest="zenpack", help="ZenPack to Dump objects.xml From", metavar="ZenPack")
def __init__(self, entry, connect=False, verbose=False, level=20, specparams=False): """Create test harness using entry. entry can be any of the following: * Filename of single YAML file. * String containing YAML. * Already-built ZenPackSpec (CFG) object. """ ZenScriptBase.__init__(self, connect=connect) ZPLTestHarness.__init__(self, entry=entry, verbose=verbose, level=level, specparams=specparams,)
def buildOptions(self): '''''' ZenScriptBase.buildOptions(self) # remove unneeded self.parser.remove_option('-C') self.parser.remove_option('--genconf') self.parser.remove_option('--genxmltable') self.parser.remove_option('--genxmlconfigs') self.parser.remove_option('--maxlogsize') self.parser.remove_option('--maxbackuplogs') self.parser.remove_option('--logpath') self.parser.usage = "%prog [options] [FILENAME|ZENPACK|DEVICE]" self.parser.version = self.version group = OptionGroup(self.parser, "ZenPack Conversion") group.add_option("-t", "--dump-templates", dest="dump", action="store_true", help="export existing monitoring templates to YAML") group.add_option("-e", "--dump-event-classes", dest="dump_event_classes", action="store_true", help="export existing event classes to YAML") group.add_option("-r", "--dump-process-classes", dest="dump_process_classes", action="store_true", help="export existing process classes to YAML") self.parser.add_option_group(group) group = OptionGroup(self.parser, "ZenPack Development") group.add_option("-c", "--create", dest="create", action="store_true", help="Create a new ZenPack source directory") group.add_option("-l", "--lint", dest="lint", action="store_true", help="check zenpack.yaml syntax for errors") group.add_option("-o", "--optimize", dest="optimize", action="store_true", help="optimize zenpack.yaml format and DEFAULTS") group.add_option("-d", "--diagram", dest="diagram", action="store_true", help="print YUML (http://yuml.me/) class diagram source based on zenpack.yaml") group.add_option("-p", "--paths", dest="paths", action="store_true", help="print possible facet paths for a given device and whether currently filtered.") self.parser.add_option_group(group)
def main(): """ Scans through zodb hierarchy (from user-supplied path, defaults to /, checking for PKEs """ execution_start = time.time() cli_options = parse_options() log = configure_logging('findposkeyerror') log.info("Command line options: %s", cli_options) if cli_options['debug']: log.setLevel(logging.DEBUG) # Attempt to get the zenoss.toolbox lock before any actions performed if not get_lock("zenoss.toolbox", log): sys.exit(1) # Obtain dmd ZenScriptBase connection dmd = ZenScriptBase(noopts=True, connect=True).dmd log.debug("ZenScriptBase connection obtained") counters = { 'item_count': Counter(0), 'error_count': Counter(0), 'repair_count': Counter(0) } processed_path = re.split("[./]", cli_options['path']) if processed_path[0] == "app": processed_path = processed_path[1:] processed_path = '/'.join(processed_path) if processed_path else '/' try: folder = dmd.getObjByPath(processed_path) except KeyError: print "Invalid path: %s" % (cli_options['path']) else: print("[%s] Examining items under the '%s' path (%s):" % (strftime("%Y-%m-%d %H:%M:%S", localtime()), cli_options['path'], folder)) log.info("Examining items under the '%s' path (%s)", cli_options['path'], folder) findPOSKeyErrors(folder, cli_options['fix'], cli_options['unlimitedram'], dmd, log, counters, cli_options['cycles']) print print("\n[%s] Execution finished in %s\n" % (strftime("%Y-%m-%d %H:%M:%S", localtime()), datetime.timedelta(seconds=int(time.time() - execution_start)))) log.info("findposkeyerror completed in %1.2f seconds", time.time() - execution_start) log.info("############################################################") if ((counters['error_count'].value() > 0) and not cli_options['fix']): print("** WARNING ** Issues were detected - Consult KB article at") print(" https://support.zenoss.com/hc/en-us/articles/203117795\n") sys.exit(1) else: sys.exit(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)
def buildOptions(self): """basic options setup sub classes can add more options here""" ZenScriptBase.buildOptions(self) self.parser.add_option('--userid', dest="userid",default="", help="name of user who is acking the event") self.parser.add_option('--evid', dest="evids", action="append", help="event id that is acked") self.parser.add_option('--state', type='int', dest="state", default=1, help="event id that is acked [default: ack]")
def parseOptions(self): ZenScriptBase.parseOptions(self) if self.args: if self.args == ['run']: sys.stderr.write('Use of "run" is deprecated.\n') elif self.args == ['help']: sys.stderr.write('Use of "help" is deprecated,' 'use --help instead.\n') self.parser.print_help() self.parser.exit() elif self.args[0]: self.parser.error('Unrecognized option(s): %s\n' % ', '.join(self.args) + 'Use --help for list of options.\n')
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option( '--collector', dest='collectorId', default='localhost', metavar='COLLECTOR_ID', help="Name of specific collector on which to run the command") self.parser.add_option( '--timeout', dest='timeout', default=60, type="int", help="Kill the process after this many seconds.")
def buildOptions(self): """ add some additional options """ ZenScriptBase.buildOptions(self) self.parser.add_option('--source', '-s', dest="source", default=None, help="Specify user id to use as a the source dashboard configuration.") self.parser.add_option('--target', "-t", dest="target", default=None, help="Specify user id to push the dashboard configuration to.") self.parser.add_option('--capfile', '-f', type="str", dest="capfile", default=None, help="When specified the capture file will be used as a target or source for a dashboard configuration.")
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option('--export', dest='export', action='store_true', default=False, help='Perform an XML export of an object') self.parser.add_option('--object', dest='object', help='Full path to the object being exported ' + '(e.g. /zport/dmd/Devices/rrdTemplates/Oracle Tablespaces)') self.parser.add_option('--import', dest='imprt', action='store_true', default=False, help='Perform an import of an object from XML') self.parser.add_option('--file', dest='file', help='Filename to of XML to import')
def go(driver): from Products.ZenUtils.ZenScriptBase import ZenScriptBase from ZenPacks.zenoss.ZenMailTx.MailTxConfigService import MailTxConfigService zendmd = ZenScriptBase(noopts=True, connect=True) dmd = zendmd.dmd d = dmd.Devices.findDevice(device) if not d: sys.stderr.write("Unable to find device %s\n" % device) sys.exit(1) log.setLevel(logging.DEBUG) service = MailTxConfigService(dmd, d.perfServer().id) if not service: sys.stderr.write("Unable to find configuration for %s" % device) proxy = service.remote_getDeviceConfigs([device]) if proxy: proxy = proxy[0] else: raise ValueError( "Unable to find a valid MailTx config for device %s" % device) config = proxy.datasources if datasource: config = [c for c in proxy.datasources if c.name == datasource] if not config: raise ValueError( "Unable to find a MailTx config %s for device %s" % (datasource or '', device)) config = config[0] config.ignoreIds = set() now = time.time() yield sendMessage(config) log.debug("Result of message send: %s", driver.next()) yield getMessage(config, 5.0) log.debug("Result of message fetch: %s", driver.next()) log.info("Message delivered in %.2f seconds" % (time.time() - now))
def buildOptions(self): """ add some additional options """ ZenScriptBase.buildOptions(self) self.parser.add_option('--organizer', dest="orgname",default=None, help="specify the organizer for which you'd like to query software for, "\ "this setting will take presedence over the devices setting") self.parser.add_option('--device', dest="devices", type="str", default=None, action="append", help="specify the device(s) you want to query software for") self.parser.add_option('--settype', type="str", dest="settype", default=None, help="specify which type of set operation you'd like to perform, \ i.e. union, difference, intersection")
class ModelCatalogUtils(object): def __init__(self, dmd=None): self.model_index = zope.component.createObject('ModelIndex', get_solr_config()) self.dmd = dmd def _get_zodb_connection(self): print("Connecting to zodb...") from Products.ZenUtils.ZenScriptBase import ZenScriptBase self.dmd = ZenScriptBase(connect=True).dmd def _get_object(self, uid): obj = None if not self.dmd: self._get_zodb_connection() try: obj = self.dmd.unrestrictedTraverse(uid) except: print "Object not found: {}".format(uid) return obj def index_by_uid(self, uid): obj = self._get_object(uid) if obj: self.model_index.index(obj) def unindex_by_uid(self, uid): query={UID: uid} search_params=SearchParams(query=query) self.model_index.unindex_search(search_params, collection=ZENOSS_MODEL_COLLECTION_NAME) def generate_indexing_event(self, uid): obj = self._get_object(uid) if obj: notify(IndexingEvent(obj))
def get_device_properties(slots): """Retrieve device attributes from Zenoss and store in local data structure (slots). """ dmd = ZenScriptBase(connect=True).dmd for device in dmd.Devices.getSubDevices(): groups = device.getDeviceGroupNames() for a in range(0, len(groups)): if groups[a].find(groupName) != -1: slot = device.rackSlot slotWords = (str(slot)).split() slotNum = int(slotWords[len(slotWords) - 1]) serialNum = device.getHWSerialNumber() name = device.getDeviceName() ip = device.getManageIp() classPath = device.getDeviceClassPath() classPath.strip() classes = classPath.split('/') className = classes[len(classes) - 1] # NOTE: Temporary hack to accommodate 1900 if slotNum == 1: if name.find("ZX1900BaseDevice") != -1: slotNum = 2 # Store info in slots slotInfo = slots[slotNum] slotInfo['ip'] = ip slotInfo['name'] = name slotInfo['serial'] = serialNum slotInfo['class'] = className
def set_device_properties(slots): """Use local data structure (slots) to set device attributes in Zenoss. """ # Set serial number, slot & name. # Zenoss will overwrite serial number & slot for Znyx devices. # So, only set these values for ZXSBC devices. # NOTE: Add error handling & logging. dmd = ZenScriptBase(connect=True).dmd for device in dmd.Devices.getSubDevices(): for slotNum in range(0, len(slots)): slotInfo = slots[slotNum] # Skip empty slots if slotInfo['serial'] == None: continue if slotInfo['ip'] == device.getManageIp(): #if device.id != device.getDeviceName(): device.renameDevice(slotInfo['name']) manf = device.getOSManufacturerName() if not manf.find("Znyx") != -1: device.setHWSerialNumber(slotInfo['serial']) device.rackSlot = slotNum dmd.Devices.reIndex() commit()
def main(): """Scans catalogs, reindexes if needed, and prints a summary""" cmdLineOptions = parse_options() dmd = ZenScriptBase(noopts=True, connect=True).dmd catalogList = [ dmd.global_catalog, dmd.Networks.ipSearch, dmd.IPv6Networks.ipSearch, dmd.Devices.deviceSearch, dmd.Services.serviceSearch, dmd.ZenLinkManager.layer2_catalog, dmd.ZenLinkManager.layer3_catalog, dmd.maintenanceWindowSearch, dmd.zenPackPersistence, dmd.Manufacturers.productSearch ] for catalog in catalogList: scan_catalog(catalog, cmdLineOptions['fix']) if cmdLineOptions['fix']: print "" print "Reindexing dmd Objects..." try: dmd.Devices.reIndex() dmd.Events.reIndex() dmd.Manufacturers.reIndex() dmd.Networks.reIndex() except Exception, e: summaryMsg.append("") summaryMsg.append(" ** Exception encountered when reindexing dmd object %s" % (e))
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option('--url', '-u', dest='url', default=None, help='URL of report to send') self.parser.add_option('--user', '-U', dest='user', default='admin', help="User to log into Zenoss") self.parser.add_option('--passwd', '-p', dest='passwd', help="Password to log into Zenoss") self.parser.add_option('--address', '-a', dest='addresses', default=[], action='append', help='Email address destination ' '(may be given more than once). Default value' "comes from the user's profile.") self.parser.add_option('--subject', '-s', dest='subject', default='', help='Subject line for email message.' 'Default value is the title of the html page.') self.parser.add_option('--from', '-f', dest='fromAddress', default='zenoss@localhost', help='Origination address') self.parser.add_option('--div', '-d', dest='div', default='contentPane', help='DIV to extract from URL') self.parser.add_option( '--comment', '-c', dest='comment', default='Report CSV attached.', help='Comment to include in body of CSV reports')
def main(): '''Performs reindex call on different DMD categories (used to be a part of zencatalogscan)''' execution_start = time.time() cli_options = parse_options() log = configure_logging('zenindextool') log.info("Command line options: %s" % (cli_options)) if cli_options['debug']: log.setLevel(logging.DEBUG) # Attempt to get the zenoss.toolbox lock before any actions performed if not get_lock("zenoss.toolbox", log): sys.exit(1) # Obtain dmd ZenScriptBase connection dmd = ZenScriptBase(noopts=True, connect=True).dmd log.debug("ZenScriptBase connection obtained") any_issue = False # Else build list of catalogs, then process catalog(s) and perform reindex if --fix types_to_reIndex = { 'Devices': 'dmd.Devices', 'Events': 'dmd.Events', 'Manufacturers': 'dmd.Manufacturers', 'Networks': 'dmd.Networks', 'Services': 'dmd.Services' } if cli_options['list'] or not cli_options['type']: # Output list of present catalogs to the UI, perform no further operations print "List of dmd types that support reIndex() calls from this script:\n" print "\n".join(types_to_reIndex.keys()) log.info( "Zenreindextool finished - list of supported types output to CLI") else: if cli_options['type'] in types_to_reIndex.keys(): any_issue = reindex_dmd_objects( cli_options['type'], types_to_reIndex[cli_options['type']], dmd, log) # exit with error if there are any issues if any_issue == False: exit(1) else: print("Type '%s' unrecognized - unable to reIndex()" % (cli_options['type'])) log.error("CLI input '%s' doesn't match recognized types" % (cli_options['type'])) exit(1) # Print final status summary, update log file with termination block print("\n[%s] Execution finished in %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), datetime.timedelta(seconds=int(time.time() - execution_start)))) log.info("zenindextool completed in %1.2f seconds" % (time.time() - execution_start)) log.info("############################################################")
def buildOptions(self): """basic options setup sub classes can add more options here""" ZenScriptBase.buildOptions(self) self.parser.add_option('--userid', dest="userid", default="", help="name of user who is acking the event") self.parser.add_option('--evid', dest="evids", action="append", help="event id that is acked") self.parser.add_option('--state', type='int', dest="state", default=1, help="event id that is acked [default: ack]")
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option( '--collector', dest='collector', help="Name of specific collector on which to run the command") self.parser.add_option( '--timeout', dest='timeout', default=60, type="int", help="Kill the process after this many seconds.") self.parser.add_option( '-n', '--useprefix', action='store_false', dest='useprefix', default=True, help="Prefix the collector name for remote servers")
def main(): parser = argparse.ArgumentParser(description="Find POSKeyErrors 1.4") parser.add_argument( "folder", metavar="PATH", type=str, help="Object path where to start searching from. E.g. Devices.Server") parser.add_argument("--fixrels", action="store_true", default=False, help="Automatically fix ZenRelationship objects") args = parser.parse_args() #import pdb; pdb.set_trace() # Configure NullHandler for logging to suppress 'no handler for # logger' messages. logger = logging.getLogger() logger.addHandler(logging.NullHandler()) ZenScriptBase.doesLogging = False # disable logging configuration dmd = ZenScriptBase(noopts=True, connect=True).dmd # Split along '/' and '.' delimiters path = re.split("[./]", args.folder) # If the first path element is 'app' (name of root node in zendmd), # then remove it from the path, because that name doesn't actually # exist in the database. if path[0] == "app": path = path[1:] # Rebuild path using '/' delimiter path = '/'.join(path) if path else '/' try: folder = dmd.getObjByPath(path) except KeyError: print "Invalid path: %s" % (args.folder, ) else: for exname, ex, objType, objId, parentPath in findPOSKeyErrors(folder): print "%s: %s on %s '%s' of %s" \ % (exname, ex, objType, objId, _getPathStr(parentPath)) # example == POSKeyError: 0x0118ef28 on relationship 'dependents' of app.zport.dmd.Devices.VMware.TNL1DMZVC01.Hosts.devices.TNL1DMZVC01_host-125.hw if args.fixrels: if isinstance(ex, POSKeyError): fixPOSKeyError(exname, ex, objType, objId, parentPath)
def buildOptions(self): ZenScriptBase.buildOptions(self) self.parser.add_option('--age', dest='age', type='int', default=1, help="Number of days old to consider fresh (default=1)") self.parser.add_option('--all', dest='all', action="store_true", default=False, help="Check all data points. Not just ones used in graphs") self.parser.add_option('--pathcache', dest='pathcache', action="store_true", default=False, help="Cache the full list of RRD file paths in the model") self.parser.add_option('--devicesonly', dest='devicesonly', action="store_true", default=False, help="Only check for device files. Not components") self.parser.add_option('--collector', dest='collector', help="Name of specific collector to check (optional)") self.parser.add_option('-o', '--file', dest='file', help="Output filename") self.parser.add_option('--sendevent', dest='sendevent', action="store_true", default=False, help="Send an event with statistics per collector")