本文整理汇总了Python中event.Event.state方法的典型用法代码示例。如果您正苦于以下问题:Python Event.state方法的具体用法?Python Event.state怎么用?Python Event.state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类event.Event
的用法示例。
在下文中一共展示了Event.state方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: join
# 需要导入模块: from event import Event [as 别名]
# 或者: from event.Event import state [as 别名]
def join(self):
try:
stdout, stderr, returncode = SubProcessTask.join(self)
event = Event()
event.service = self.name
event.ttl = self.ttl * self.ttl_multiplier
event.host = self.host
event.tags = self.tags
event.attributes = self.attributes
output, attributes = self.parse_nagios_output(stdout)
event.description = "Note: %s\nCommand: %s\nOutput: %s\n" % (self.note, self.raw_command, output)
if returncode in self.exitcodes:
event.state = self.exitcodes[returncode]
else:
event.state = 'unknown'
if attributes:
if 'metric' in self.config and self.config['metric'] in attributes:
metric_key = self.config['metric']
else:
metric_key = attributes.keys()[0]
event.attributes.update(attributes)
event.metric = float(NUMERIC_REGEX.match(attributes[metric_key]).group(1))
self.events.append(event)
except Exception as e:
log.error("Exception joining task '%s':\n%s" % (self.name, str(e)))
示例2: join
# 需要导入模块: from event import Event [as 别名]
# 或者: from event.Event import state [as 别名]
def join(self):
try:
json_result = self.q.get(timeout=(self.ttl * 0.3))
self.proc.join()
log.debug('CloudKickTask: Processing %s metrics' % (len(json_result['metrics'])))
for metric in json_result['metrics']:
note = metric['note'] if 'note' in metric else self.note
event = Event()
event.ttl = self.ttl * self.ttl_multiplier
event.host = self.host
event.tags = self.tags
event.service = metric['name']
event.state = metric['state']
event.metric = metric['value']
event.description = "%s\nWarn threshold: %s, Error threshold: %s" % (note,
metric['warn_threshold'],
metric['error_threshold'])
if 'attributes' in metric:
event.attributes = metric['attributes']
self.events.append(event)
except Exception as e:
log.error("Exception joining CloudKickTask '%s'\n%s" % (self.name, traceback.format_exc()))
self.locked = False
示例3: join
# 需要导入模块: from event import Event [as 别名]
# 或者: from event.Event import state [as 别名]
def join(self):
try:
stdout, stderr, returncode = SubProcessTask.join(self)
try:
results = json.loads(stdout)
except Exception as e:
log.error("Failed to parse JSON. '%s':\n%s" % (self.name, str(e)))
return
for result in results:
for field in ['service', 'state', 'description', 'metric']:
if field not in result:
log.error("Event missing field '%s'" % (field))
continue
event = Event()
event.ttl = self.ttl * self.ttl_multiplier
event.attributes = dict(self.attributes)
if 'host' in result and result['host'] is not None:
event.host = result['host']
else:
event.host = self.host
if 'tags' in result and result['tags'] is not None:
event.tags = self.tags.union(result['tags'])
else:
event.tags = self.tags
if "attributes" in result:
attributes = result["attributes"]
event.attributes.update(dict((self.clean_attribute_name(key), attributes[key]) for key in attributes))
event.service = result['service']
event.state = result['state']
event.metric = result['metric']
event.description = "%s\n%s" % (self.note, result['description'])
self.events.append(event)
except Exception as e:
log.exception("Exception joining task '%s':\n%s" % (self.name, str(e)))