monit: add support for all monit services when checking process state (#1532) (#1578)

* add support for all monit service types

* ignore case when performing check

* add changelog

* Escape special characters before matching

Co-authored-by: Felix Fontein <felix@fontein.de>

* escape each element individually

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit bed1dc479f)

Co-authored-by: Graham Herceg <g.a.herceg@gmail.com>
This commit is contained in:
patchback[bot] 2021-01-03 11:47:54 +00:00 committed by GitHub
parent 56055d4f1e
commit 4f7d44aa10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 12 deletions

View file

@ -62,6 +62,9 @@ STATE_COMMAND_MAP = {
'restarted': 'restart'
}
MONIT_SERVICES = ['Process', 'File', 'Fifo', 'Filesystem', 'Directory', 'Remote host', 'System', 'Program',
'Network']
@python_2_unicode_compatible
class StatusValue(namedtuple("Status", "value, is_pending")):
@ -151,7 +154,9 @@ class Monit(object):
return self._parse_status(out, err)
def _parse_status(self, output, err):
if "Process '%s'" % self.process_name not in output:
escaped_monit_services = '|'.join([re.escape(x) for x in MONIT_SERVICES])
pattern = "(%s) '%s'" % (escaped_monit_services, re.escape(self.process_name))
if not re.search(pattern, output, re.IGNORECASE):
return Status.MISSING
status_val = re.findall(r"^\s*status\s*([\w\- ]+)", output, re.MULTILINE)