Commit f08b3dd7 authored by Matthew Smith's avatar Matthew Smith
Browse files

space formatting only

parent 42b7c6ff
......@@ -97,9 +97,9 @@ if not host_address:
# Email subject
if host_state:
EMAILMESSAGE = 'Host ' + notification_type + ' - ' + host_display_name + ' is ' + host_state
EMAILMESSAGE = 'Host ' + notification_type + ' - ' + host_display_name + ' is ' + host_state
elif service_state:
EMAILMESSAGE = 'Service ' + notification_type + ' - ' + host_display_name + ' service ' + service_display_name + ' is ' + service_state
EMAILMESSAGE = 'Service ' + notification_type + ' - ' + host_display_name + ' service ' + service_display_name + ' is ' + service_state
# With debug on each run produces a template that can be rerun for testing
......@@ -177,9 +177,9 @@ class Netbox:
headers.update({ 'Authorization': 'Token ' + NETBOXTOKEN })
response = requests.get(url, headers=headers)
if DEBUG:
print("Netbox response: ")
print(response)
print(response.json())
print("Netbox response: ")
print(response)
print(response.json())
return response.json()
def searchNetboxData(self, url):
......@@ -221,27 +221,27 @@ class Grafana:
self.page_url = ''
self.png = None
self.icingaweb2_ini = None
self.panelID = None
self.panelID = None
if GRAFANAICINGAWEB2INI:
self.__parseIcingaweb2INI()
if GRAFANAICINGAWEB2INI:
self.__parseIcingaweb2INI()
if service_state:
self.panelID = self.__getPanelID(service_display_name, service_name, service_command)
if host_state:
self.panelID = grafana_host_panel_id
self.panelID = grafana_host_panel_id
if self.panelID:
self.png_url = GRAFANABASE + '/render/dashboard-solo/db/' + GRAFANADASHBOARD + '?panelId=' + self.panelID + '&' + GRAFANAVARHOST + '=' + netbox_host_name + '&theme=' + GRAFANATHEME + '&width=' + WIDTH + '&height=' + HEIGHT
self.page_url = GRAFANABASE + '/dashboard/db/' + GRAFANADASHBOARD + '?fullscreen&panelId=' + self.panelID + '&' + GRAFANAVARHOST + '=' + netbox_host_name
self.png = self.__getPNG()
def __parseIcingaweb2INI(self):
def __parseIcingaweb2INI(self):
if DEBUG:
print("\nGrafana ini file: {}".format(GRAFANAICINGAWEB2INI))
self.icingaweb2_ini = ConfigParser.ConfigParser()
self.icingaweb2_ini.read(GRAFANAICINGAWEB2INI)
self.icingaweb2_ini = ConfigParser.ConfigParser()
self.icingaweb2_ini.read(GRAFANAICINGAWEB2INI)
def __getPNG(self):
headers = {'Authorization': 'Bearer ' + GRAFANAAPIKEY}
......@@ -253,36 +253,36 @@ class Grafana:
print(response.status_code)
return response
def __searchSections(self, display_name, name, command):
pattern = None
if display_name:
pattern = re.compile(display_name)
if name and pattern == None:
pattern = re.compile(name)
if command and pattern == None:
pattern = re.compile(command)
def __searchSections(self, display_name, name, command):
pattern = None
if display_name:
pattern = re.compile(display_name)
if name and pattern == None:
pattern = re.compile(name)
if command and pattern == None:
pattern = re.compile(command)
if DEBUG:
print("\nGrafana ini sections: {}".format(self.icingaweb2_ini.sections()))
print("\nGrafana ini pattern: {}".format(pattern))
section = None
if pattern:
section = filter(pattern.match, self.icingaweb2_ini.sections())
if DEBUG:
print("\nGrafana section: {}".format(section))
if len(section) == 1:
section = section[0]
section = None
if pattern:
section = filter(pattern.match, self.icingaweb2_ini.sections())
if DEBUG:
print("\nGrafana section: {}".format(section))
if len(section) == 1:
section = section[0]
if DEBUG:
print("\nGrafana section: {}".format(section))
return section
return section
def __getPanelID(self, display_name, name, command):
section = self.__searchSections(display_name, name, command)
panel_id = None
if section:
panel_id = self.icingaweb2_ini.get(section, 'panelId').replace('"', '')
return panel_id
def __getPanelID(self, display_name, name, command):
section = self.__searchSections(display_name, name, command)
panel_id = None
if section:
panel_id = self.icingaweb2_ini.get(section, 'panelId').replace('"', '')
return panel_id
netbox = Netbox()
......@@ -346,9 +346,9 @@ HTML += '\n<tr><th>IP Address:</th><td>' + host_address + '</td></tr>'
HTML += '\n<tr><th>Status:</th><td>' + host_state + service_state + '</td></tr>'
HTML += '\n<tr><th>Service Name:</th><td>' + service_display_name + '</td></tr>'
if host_state:
HTML += '\n<tr><th>Service Data:</th><td><a style="color: #0095bf; text-decoration: none;" href="' + ICINGA2BASE + '/monitoring/host/services?host=' + host_alias + '">' + host_output + '</a></td></tr>'
HTML += '\n<tr><th>Service Data:</th><td><a style="color: #0095bf; text-decoration: none;" href="' + ICINGA2BASE + '/monitoring/host/services?host=' + host_alias + '">' + host_output + '</a></td></tr>'
if service_state:
HTML += '\n<tr><th>Service Data:</th><td><a style="color: #0095bf; text-decoration: none;" href="' + ICINGA2BASE + '/monitoring/service/show?host=' + host_alias + '&service=' + service_name + '">' + service_output + '</a></td></tr>'
HTML += '\n<tr><th>Service Data:</th><td><a style="color: #0095bf; text-decoration: none;" href="' + ICINGA2BASE + '/monitoring/service/show?host=' + host_alias + '&service=' + service_name + '">' + service_output + '</a></td></tr>'
HTML += '\n<tr><th>Event Time:</th><td>' + long_date_time + '</td></tr>'
if (notification_author and notification_comment):
......@@ -407,7 +407,7 @@ if grafana.page_url:
HTML += '\n</table><br>'
HTML += '\n<table width=' + WIDTH + '>'
HTML += '\n<tr><td class=center>Generated by Icinga 2 with data from Icinga 2'
HTML += '\n<tr><td class=center>Generated by Icinga 2 with data from Icinga 2'
if grafana.panelID:
HTML += ', Grafana'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment