Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
fix pattern for matching service discovery stats
Browse files Browse the repository at this point in the history
  • Loading branch information
brennerm committed Sep 5, 2019
1 parent 27374ed commit ebd68c5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions check_mk_web_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class WebApi:
"""

__DISCOVERY_REGEX = {
'added': re.compile(r'.*Added (\d+),.*'),
'removed': re.compile(r'.*Removed (\d+),.*'),
'kept': re.compile(r'.*Kept (\d+),.*'),
'new_count': re.compile(r'.*New Count (\d+)$')
'added': [re.compile(r'.*Added (\d+),.*')],
'removed': [re.compile(r'.*([Rr])emoved (\d+),.*')],
'kept': [re.compile(r'.*([Kk])ept (\d+),.*')],
'new_count': [re.compile(r'.*New Count (\d+)$'), re.compile(r'.*(\d+) new.*')] # output changed in 1.6 so we have to try multiple patterns
}

class DiscoverMode(enum.Enum):
Expand Down Expand Up @@ -304,8 +304,12 @@ def discover_services(self, hostname, mode=DiscoverMode.NEW):
result = self.make_request('discover_services', data=data, query_params=query_params)

counters = {}
for k, regex in WebApi.__DISCOVERY_REGEX.items():
counters[k] = regex.match(result).group(1)
for k, patterns in WebApi.__DISCOVERY_REGEX.items():
for pattern in patterns:
try:
counters[k] = pattern.match(result).group(1)
except AttributeError:
continue

return counters

Expand Down

0 comments on commit ebd68c5

Please sign in to comment.