refactor: add zabbix agent support
@@ -6,6 +6,7 @@ if platform.LINUX:
class Health(Plugin):
+ AgentPluginType = 'sys'
DEFAULT_CONFIG = {'max_memory_usage': str(40 * 1024 * 1024)}
@@ -23,13 +24,14 @@ class Health(Plugin):
def items(self, template):
# see supervisor.py:
+ if self.Type == "mamonsu":
result = template.item({
'name': 'Mamonsu: plugin errors',
'key': 'mamonsu.plugin.errors[]',
'value_type': Plugin.VALUE_TYPE.text # text
}) + template.item({
'name': 'Mamonsu: plugin keep alive',
- 'key': 'mamonsu.plugin.keepalive[]'
+ 'key': self.right_type("mamonsu.plugin.keepalive{0}")
})
if platform.LINUX:
result += template.item({
@@ -37,9 +39,15 @@ class Health(Plugin):
'key': 'mamonsu.memory.rss[max]',
'units': Plugin.UNITS.bytes
})
+ else:
+ result = template.item({
+ 'name': 'Mamonsu: plugin keep alive',
+ 'key': self.right_type("mamonsu.plugin.keepalive{0}")
+ })
return result
def triggers(self, template):
+ if self.Type == "mamonsu":
result = template.trigger({
'name': 'Mamonsu plugin errors '
'on {HOSTNAME}. {ITEM.LASTVALUE}',
@@ -47,7 +55,7 @@ class Health(Plugin):
'}&gt;1'
}) + template.trigger({
'name': 'Mamonsu nodata from {HOSTNAME}',
- 'expression': '{#TEMPLATE:mamonsu.plugin.keepalive[]'
+ 'expression': '{#TEMPLATE:' + self.right_type("mamonsu.plugin.keepalive{0}") +
'.nodata(180)}=1'
})
if platform.LINUX:
@@ -57,4 +65,16 @@ class Health(Plugin):
'expression': '{#TEMPLATE:mamonsu.memory.rss[max].last()}'
'&gt;' + self.plugin_config('max_memory_usage')
})
+ else:
+ result = template.trigger({
+ 'name': 'Mamonsu nodata from {HOSTNAME}',
+ 'expression': '{#TEMPLATE:' + self.right_type("mamonsu.plugin.keepalive{0}") +
+ '.nodata(180)}=1'
+ })
return result
+
+ def keys_and_queries(self, template_zabbix):
+ result = []
+ result.append('{0},{1}'.format("mamonsu.plugin.keepalive", "echo 0"))
+ return template_zabbix.key_and_query(result)
+
