Skip to content

Commit

Permalink
Merge pull request #983 from BenoitPoulet/master
Browse files Browse the repository at this point in the history
Centreon fixes for 23.10
  • Loading branch information
HenriWahl authored Nov 14, 2023
2 parents fd38f1b + f9d1a7c commit 31cfcd1
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions Nagstamon/Servers/Centreon/CentreonAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ def init_config(self):
self.restapi_version = "latest"
elif self.centreon_version_major == 22:
self.restapi_version = "v22.04"
else:
elif self.centreon_version_major == 23 and self.centreon_version_minor == 4:
self.restapi_version = "v23.04"
else:
self.restapi_version = "v23.10"
if conf.debug_mode is True:
self.Debug(server='[' + self.get_name() + ']', debug='Centreon API version used : ' + self.restapi_version)

Expand Down Expand Up @@ -347,7 +349,7 @@ def _get_status(self):
self.new_hosts[new_host] = GenericHost()
self.new_hosts[new_host].name = alerts["name"]
self.new_hosts[new_host].server = self.name
# API inconsistency, even by fixing exact version number
# API inconsistency, even by fixing exact version number, changed starting with 22.04
if self.centreon_version_major == 21 or (self.centreon_version_major == 22 and self.centreon_version_minor == 4):
self.new_hosts[new_host].criticality = alerts["severity_level"]
else:
Expand All @@ -358,13 +360,20 @@ def _get_status(self):
self.new_hosts[new_host].duration = alerts["duration"]
self.new_hosts[new_host].attempt = alerts["tries"]
self.new_hosts[new_host].status_information = alerts["information"]
self.new_hosts[new_host].passiveonly = alerts["passive_checks"]
self.new_hosts[new_host].notifications_disabled = not alerts["notification_enabled"]
# Change starting with 23.10
if (self.centreon_version_major >= 23 and self.centreon_version_minor >= 10) or self.centreon_version_major > 23:
self.new_hosts[new_host].passiveonly = alerts["has_passive_checks_enabled"]
self.new_hosts[new_host].notifications_disabled = not alerts["is_notification_enabled"]
self.new_hosts[new_host].acknowledged = alerts["is_acknowledged"]
self.new_hosts[new_host].scheduled_downtime = alerts["is_in_downtime"]
else:
self.new_hosts[new_host].passiveonly = alerts["passive_checks"]
self.new_hosts[new_host].notifications_disabled = not alerts["notification_enabled"]
self.new_hosts[new_host].acknowledged = alerts["acknowledged"]
self.new_hosts[new_host].scheduled_downtime = alerts["in_downtime"]
# avoid crash if flapping is not configured in Centreon
# according to https://github.com/HenriWahl/Nagstamon/issues/866#issuecomment-1302257034
self.new_hosts[new_host].flapping = alerts.get("flapping", False)
self.new_hosts[new_host].acknowledged = alerts["acknowledged"]
self.new_hosts[new_host].scheduled_downtime = alerts["in_downtime"]
if "(S)" in alerts["tries"]:
self.new_hosts[new_host].status_type = self.HARD_SOFT['(S)']
else:
Expand Down Expand Up @@ -425,18 +434,25 @@ def _get_status(self):
self.new_hosts[new_host].services[new_service].duration = alerts["duration"]
self.new_hosts[new_host].services[new_service].attempt = alerts["tries"]
self.new_hosts[new_host].services[new_service].status_information = alerts["information"]
self.new_hosts[new_host].services[new_service].passiveonly = alerts["passive_checks"]
self.new_hosts[new_host].services[new_service].notifications_disabled = not alerts["notification_enabled"]
# Change starting with 23.10
if (self.centreon_version_major >= 23 and self.centreon_version_minor >= 10) or self.centreon_version_major > 23:
self.new_hosts[new_host].services[new_service].passiveonly = alerts["has_passive_checks_enabled"]
self.new_hosts[new_host].services[new_service].notifications_disabled = not alerts["is_notification_enabled"]
self.new_hosts[new_host].services[new_service].acknowledged = alerts["is_acknowledged"]
self.new_hosts[new_host].services[new_service].scheduled_downtime = alerts["is_in_downtime"]
else:
self.new_hosts[new_host].services[new_service].passiveonly = alerts["passive_checks"]
self.new_hosts[new_host].services[new_service].notifications_disabled = not alerts["notification_enabled"]
self.new_hosts[new_host].services[new_service].acknowledged = alerts["acknowledged"]
self.new_hosts[new_host].services[new_service].scheduled_downtime = alerts["in_downtime"]
# avoid crash if flapping is not configured in Centreon
# according to https://github.com/HenriWahl/Nagstamon/issues/866#issuecomment-1302257034
self.new_hosts[new_host].services[new_service].flapping = alerts.get("flapping", False)
self.new_hosts[new_host].services[new_service].acknowledged = alerts["acknowledged"]
self.new_hosts[new_host].services[new_service].scheduled_downtime = alerts["in_downtime"]
if "(S)" in alerts["tries"]:
self.new_hosts[new_host].services[new_service].status_type = self.HARD_SOFT['(S)']
else:
self.new_hosts[new_host].services[new_service].status_type = self.HARD_SOFT['(H)']
# API inconsistency, even by fixing exact version number
# API inconsistency, even by fixing exact version number, changed starting with 22.04
if self.centreon_version_major == 21 or (self.centreon_version_major == 22 and self.centreon_version_minor == 4):
self.new_hosts[new_host].services[new_service].criticality = alerts["severity_level"]
else:
Expand Down Expand Up @@ -552,7 +568,7 @@ def _set_recheck(self, host, service):
}

# This new parameter was added in 23.04
if self.restapi_version == "v23.04":
if self.centreon_version_major >= 23:
property_to_add = {
"check": {
"is_forced": True
Expand Down

0 comments on commit 31cfcd1

Please sign in to comment.