Skip to content

Instantly share code, notes, and snippets.

@cluther
Last active March 29, 2018 16:41
Show Gist options
  • Save cluther/f275eefc12a2f1ee821b765816d17681 to your computer and use it in GitHub Desktop.
Save cluther/f275eefc12a2f1ee821b765816d17681 to your computer and use it in GitHub Desktop.
NetBotzStatus.py
from twisted.spread import pb
from Products.ZenModel.ThresholdClass import ThresholdClass
from Products.ZenModel.ThresholdInstance import ThresholdContext
from Products.ZenModel.ThresholdInstance import MetricThresholdInstance
class NetBotzStatus(ThresholdClass):
meta_type = "NetBotz Status"
eventClass = "/Status"
severity = 2
def createThresholdInstance(self, context):
return NetBotzStatusInstance(
self.id,
ThresholdContext(context),
# ThresholdClass properties.
self.dsnames,
eventClass=self.eventClass,
severity=self.severity)
class NetBotzStatusInstance(MetricThresholdInstance):
def checkValue(self, dataPoint, timestamp, value):
severity_map = {
0: 0, # clear
1: 2, # info
2: 3, # warning
3: 4, # error
4: 5, # critical
5: 5, # failure
}
label_map = {
0: "normal",
1: "info",
2: "warning",
3: "error",
4: "critical",
5: "failure",
}
context = self.context()
int_value = int(value)
severity = severity_map.get(int_value, 2)
label = label_map.get(int_value, "unknown")
return [{
# mandatory event fields
"device": context.deviceName,
"severity": severity,
"summary": "temperature sensor status: {}".format(label),
# additional event fields
"component": context.componentName,
"eventClass": self.eventClass,
"eventKey": self.id,
}]
# Allow NetBotzStatusInstance to be sent from zenhub to collectors.
pb.setUnjellyableForClass(NetBotzStatusInstance, NetBotzStatusInstance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment