Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sol1 Icinga
icinga2-enhanced-mail-notification
Commits
f08b3dd7
Commit
f08b3dd7
authored
Dec 12, 2018
by
Matthew Smith
Browse files
space formatting only
parent
42b7c6ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
enhanced-mail-notification.py
View file @
f08b3dd7
...
...
@@ -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
(
"
\n
Grafana 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
(
"
\n
Grafana ini sections: {}"
.
format
(
self
.
icingaweb2_ini
.
sections
()))
print
(
"
\n
Grafana ini pattern: {}"
.
format
(
pattern
))
section
=
None
if
pattern
:
section
=
filter
(
pattern
.
match
,
self
.
icingaweb2_ini
.
sections
())
if
DEBUG
:
print
(
"
\n
Grafana 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
(
"
\n
Grafana section: {}"
.
format
(
section
))
if
len
(
section
)
==
1
:
section
=
section
[
0
]
if
DEBUG
:
print
(
"
\n
Grafana 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'
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment