Skip to content

Instantly share code, notes, and snippets.

@technovangelist
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save technovangelist/2f2a117cd9a6f4e7323e to your computer and use it in GitHub Desktop.

Select an option

Save technovangelist/2f2a117cd9a6f4e7323e to your computer and use it in GitHub Desktop.
MyCustomCheck.py
from checks import AgentCheck
import re
import psutil
class CheckProcessNotRunning(AgentCheck):
def check(self, instance):
search = instance['search']
running_names = [p.name().strip() for p in psutil.process_iter()]
matched = len([n for n in running_names if re.match(search, n)])
if matched > 0:
status = AgentCheck.ALERT
else:
status = AgentCheck.OK
message = "OMG!!! %s is running" % search
self.service_check('sample.check_proc_not_running', status, tags=['search:%s' % search, 'test'], message=
message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment