本文整理汇总了Python中Products.ZenUtils.ZenScriptBase.ZenScriptBase.getObjByPath方法的典型用法代码示例。如果您正苦于以下问题:Python ZenScriptBase.getObjByPath方法的具体用法?Python ZenScriptBase.getObjByPath怎么用?Python ZenScriptBase.getObjByPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.ZenUtils.ZenScriptBase.ZenScriptBase
的用法示例。
在下文中一共展示了ZenScriptBase.getObjByPath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import getObjByPath [as 别名]
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)
示例2: processAll
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import getObjByPath [as 别名]
def processAll(options):
dmd = ZenScriptBase(connect=True).dmd
devpath = dmd.getObjByPath('/zport/dmd' + options.path)
print "Processing Devices under %s" % options.path
print "Turning %s processes/ip services\n" % prettyAction(options.action)
if not devpath:
raise OptionValueError("Path %s does not exist, " +
"please specify existing path" \
% options.path)
sys.exit(1)
todos = {}
if options.process:
todos["processes"] = options.process.split(",")
if options.ipservice:
todos["ipservices"] = options.ipservice.split(",")
for d in devpath.getSubDevices():
for todo, procs in todos.items():
processDevice(todo, d, procs, options.action)
示例3: main
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import getObjByPath [as 别名]
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)
示例4: ZenScriptBase
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import getObjByPath [as 别名]
#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)
示例5: getFacade
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import getObjByPath [as 别名]
from transaction import commit
# Edit the things below
myDeviceClass = "/zport/dmd/Devices/Server/Linux/RSA"
myTemplate = "Device_RSA"
#Don't edit below here unless you REALLY MEAN IT
myTemplatePath = myDeviceClass + "/rrdTemplates/" + myTemplate
myDataSource = myDataPoint = sys.argv[1]
myDataSourcePath = myTemplatePath + "/datasources/" + myDataSource
myOID = sys.argv[2]
myDataPointPath = myDataSourcePath + "/datapoints/" + myDataPoint
try:
#find out if the datapoint already exists
dmd.getObjByPath(myDataPointPath)
except:
#an except means it doesn't, so create it.
facade = getFacade("template")
facade.addTemplate(myTemplate, myDeviceClass)
facade.addDataSource(myTemplatePath, myDataSource, "SNMP")
facade.setInfo(myDataSourcePath, {'oid':myOID})
facade.addDataPoint(myDataSourcePath, myDataPoint)
try:
commit()
except:
#sometimes a commit doesn't work because
#of concurrent reads or whatever.
#if so, just sleep for a sec and retry
print "retrying last."
import time
示例6: main
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import getObjByPath [as 别名]
def main():
""" Scans through zodb hierarchy (from user-supplied path, defaults to /, checking for PKEs """
execution_start = time.time()
scriptName = os.path.basename(__file__).split('.')[0]
parser = ZenToolboxUtils.parse_options(scriptVersion, scriptName + scriptSummary + documentationURL)
# Add in any specific parser arguments for %scriptName
parser.add_argument("-f", "--fix", action="store_true", default=False,
help="attempt to fix ZenRelationship objects")
parser.add_argument("-n", "--cycles", action="store", default="2", type=int,
help="maximum times to cycle (with --fix)")
parser.add_argument("-p", "--path", action="store", default="/", type=str,
help="base path to scan from (Devices.Server)?")
parser.add_argument("-u", "--unlimitedram", action="store_true", default=False,
help="skip transaction.abort() - unbounded RAM, ~40%% faster")
cli_options = vars(parser.parse_args())
log, logFileName = ZenToolboxUtils.configure_logging(scriptName, scriptVersion, cli_options['tmpdir'])
log.info("Command line options: %s" % (cli_options))
if cli_options['debug']:
log.setLevel(logging.DEBUG)
print "\n[%s] Initializing %s v%s (detailed log at %s)" % \
(time.strftime("%Y-%m-%d %H:%M:%S"), scriptName, scriptVersion, logFileName)
# Attempt to get the zenoss.toolbox lock before any actions performed
if not ZenToolboxUtils.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': ZenToolboxUtils.Counter(0),
'error_count': ZenToolboxUtils.Counter(0),
'repair_count': ZenToolboxUtils.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 not cli_options['skipEvents']:
if counters['error_count'].value():
eventSeverity = 4
eventSummaryMsg = "%s encountered %d errors (took %1.2f seconds)" % \
(scriptName, counters['error_count'].value(), (time.time() - execution_start))
else:
eventSeverity = 2
eventSummaryMsg = "%s completed without errors (took %1.2f seconds)" % \
(scriptName, (time.time() - execution_start))
ZenToolboxUtils.send_summary_event(
eventSummaryMsg, eventSeverity,
scriptName, "executionStatus",
documentationURL, dmd
)
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)
示例7: ZenScriptBase
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import getObjByPath [as 别名]
#!/usr/bin/env python
import Globals, re, string, sys
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit
dmd = ZenScriptBase(connect=True).dmd
print 'Modeling devices in %s' % sys.argv[1]
org = dmd.getObjByPath(sys.argv[1])
org.collectDevice()