Added custom notes (/etc/check_mk/notes...).
This commit is contained in:
parent
43d4de45df
commit
e4cf60bb6d
@ -118,6 +118,71 @@ def fetch_graph(context, source, view = 1):
|
||||
|
||||
return graph
|
||||
|
||||
# Borrowed from share/check_mk/web/plugins/views/painters.py
|
||||
def notes_matching_pattern_entries(dirs, item):
|
||||
from fnmatch import fnmatch
|
||||
matching = []
|
||||
for dir in dirs:
|
||||
if os.path.isdir(dir):
|
||||
entries = filter(lambda d: d[0] != '.', os.listdir(dir))
|
||||
entries.sort()
|
||||
entries.reverse()
|
||||
for pattern in entries:
|
||||
if pattern[0] == '.':
|
||||
continue
|
||||
if fnmatch(item, pattern):
|
||||
matching.append(dir + "/" + pattern)
|
||||
return matching
|
||||
|
||||
# Borrowed and modified from share/check_mk/web/plugins/views/painters.py
|
||||
def get_custom_notes(context):
|
||||
host = context['HOSTNAME']
|
||||
svc = context.get('SERVICEDESC')
|
||||
|
||||
files_svc = []
|
||||
if svc:
|
||||
notes_dir = context["OMD_ROOT"] + "/etc/check_mk/notes/services"
|
||||
dirs = notes_matching_pattern_entries([notes_dir], host)
|
||||
files_svc = notes_matching_pattern_entries(dirs, svc)
|
||||
files_svc.sort()
|
||||
files_svc.reverse()
|
||||
|
||||
dirs = [ context["OMD_ROOT"] + "/etc/check_mk/notes/hosts" ]
|
||||
files_host = notes_matching_pattern_entries(dirs, host)
|
||||
files_host.sort()
|
||||
files_host.reverse()
|
||||
|
||||
def replace_tags(text):
|
||||
base_url = ""
|
||||
if context.get('PARAMETER_2'):
|
||||
base_url = context['PARAMETER_2'].rstrip('/')
|
||||
return text\
|
||||
.replace('$URL_PREFIX$', base_url)\
|
||||
.replace('$SITE$', context['OMD_SITE'])\
|
||||
.replace('$HOSTNAME$', host)\
|
||||
.replace('$HOSTNAME_LOWER$', host.lower())\
|
||||
.replace('$HOSTNAME_UPPER$', host.upper())\
|
||||
.replace('$HOSTNAME_TITLE$', host[0].upper() + host[1:].lower())\
|
||||
.replace('$HOSTADDRESS$', context['HOSTADDRESS'])\
|
||||
.replace('$SERVICEOUTPUT$', context.get('SERVICEOUTPUT', ""))\
|
||||
.replace('$HOSTOUTPUT$', context.get('HOSTOUTPUT', ""))\
|
||||
.replace('$SERVICEDESC$', context.get('SERVICEDESC', ""))
|
||||
|
||||
contents_host = []
|
||||
contents_svc = []
|
||||
|
||||
for f in files_host:
|
||||
contents_host.append(replace_tags(unicode(file(f).read(), "utf-8").strip()))
|
||||
|
||||
for f in files_svc:
|
||||
contents_svc.append(replace_tags(unicode(file(f).read(), "utf-8").strip()))
|
||||
|
||||
result = { "HOST": [], "SERVICE": [] }
|
||||
result["HOST"] = "\n<hr />\n".join(contents_host)
|
||||
result["SERVICE"] = "\n<hr />\n".join(contents_svc)
|
||||
|
||||
return result
|
||||
|
||||
def main():
|
||||
# gather all options from env
|
||||
context = dict([
|
||||
@ -131,6 +196,10 @@ def main():
|
||||
context['SERVICENOTES'] = os.environ.get("NAGIOS_SERVICENOTES")
|
||||
context['SERVICENOTESURL'] = os.environ.get("NAGIOS_SERVICENOTESURL")
|
||||
|
||||
notes = get_custom_notes(context)
|
||||
context['HOSTCUSTOMNOTES'] = notes["HOST"]
|
||||
context['SERVICECUSTOMNOTES'] = notes["SERVICE"]
|
||||
|
||||
# Fetch graphs for this object. It first tries to detect how many sources
|
||||
# are available for this object. Then it loops through all sources and
|
||||
# fetches retrieves the images. If a problem occurs, it is printed to
|
||||
|
@ -27,10 +27,31 @@
|
||||
<td>{{HOSTOUTPUT}}</td>
|
||||
</tr>
|
||||
{{#LONGHOSTOUTPUT}}
|
||||
<tr class="odd0">
|
||||
<td class="left">Long output</td>
|
||||
<td>{{{LONGHOSTOUTPUT}}}</td>
|
||||
</tr>
|
||||
<tr class="odd0">
|
||||
<td class="left">Long output</td>
|
||||
<td>{{{LONGHOSTOUTPUT}}}</td>
|
||||
</tr>
|
||||
{{/LONGHOSTOUTPUT}}
|
||||
{{#NOTIFICATIONCOMMENT}}
|
||||
<tr>
|
||||
<th colspan="2">Comment</th>
|
||||
</tr>
|
||||
<tr class="odd0">
|
||||
<td class="left">Text</td>
|
||||
<td>{{NOTIFICATIONCOMMENT}}</td>
|
||||
</tr>
|
||||
<tr class="even0">
|
||||
<td class="left">Author</td>
|
||||
<td>{{NOTIFICATIONAUTHORALIAS}} ({{NOTIFICATIONAUTHORNAME}})</td>
|
||||
</tr>
|
||||
{{/NOTIFICATIONCOMMENT}}
|
||||
{{#HOSTCUSTOMNOTES}}
|
||||
<tr>
|
||||
<th colspan="2">Custom Host Notes</th>
|
||||
</tr>
|
||||
<tr class="odd0">
|
||||
<td colspan="2">{{{HOSTCUSTOMNOTES}}}</td>
|
||||
</tr>
|
||||
{{/HOSTCUSTOMNOTES}}
|
||||
{{{GRAPH_CODE}}}
|
||||
</table>{{> foot_html}}
|
@ -1,7 +1,18 @@
|
||||
Host: {{HOSTNAME}} ({{HOSTALIAS}})
|
||||
Address: {{HOSTADDRESS}}
|
||||
{{HOSTLINK}}
|
||||
Address: {{HOSTADDRESS}} {{HOSTLINK}}
|
||||
{{#HOSTNOTESURL}}More Info: {{HOSTNOTESURL}}{{/HOSTNOTESURL}}
|
||||
|
||||
State: {{LASTHOSTSTATE}} -> {{HOSTSTATE}} ({{NOTIFICATIONTYPE}}) since {{LASTHOSTSTATECHANGE_REL}}
|
||||
Output: {{HOSTOUTPUT}}
|
||||
Perfdata: {{HOSTPERFDATA}}
|
||||
{{LONGHOSTOUTPUT}}
|
||||
|
||||
{{#NOTIFICATIONCOMMENT}}Comment by {{NOTIFICATIONAUTHORALIAS}} ({{NOTIFICATIONAUTHORNAME}}):
|
||||
{{NOTIFICATIONCOMMENT}}
|
||||
|
||||
{{/NOTIFICATIONCOMMENT}}
|
||||
{{#HOSTCUSTOMNOTES}}
|
||||
Custom Host Notes:
|
||||
{{{HOSTCUSTOMNOTES}}}
|
||||
|
||||
{{/HOSTCUSTOMNOTES}}
|
||||
|
@ -11,6 +11,14 @@
|
||||
<td class=left>Address</td>
|
||||
<td>{{HOSTADDRESS}}</td>
|
||||
</tr>
|
||||
{{#HOSTCUSTOMNOTES}}
|
||||
<tr>
|
||||
<th colspan="2">Custom Host Notes</th>
|
||||
</tr>
|
||||
<tr class="odd0">
|
||||
<td colspan="2">{{{HOSTCUSTOMNOTES}}}</td>
|
||||
</tr>
|
||||
{{/HOSTCUSTOMNOTES}}
|
||||
<tr class="odd0">
|
||||
<td class=left>Service description</td>
|
||||
<td>{{{LINKEDSERVICEDESC}}}{{#SERVICENOTESURL}} [<a href="{{SERVICENOTESURL}}">More info</a>]{{/SERVICENOTESURL}}</td>
|
||||
@ -49,5 +57,13 @@
|
||||
<td>{{NOTIFICATIONAUTHORALIAS}} ({{NOTIFICATIONAUTHORNAME}})</td>
|
||||
</tr>
|
||||
{{/NOTIFICATIONCOMMENT}}
|
||||
{{#SERVICECUSTOMNOTES}}
|
||||
<tr>
|
||||
<th colspan="2">Custom Service Notes</th>
|
||||
</tr>
|
||||
<tr class="odd0">
|
||||
<td colspan="2">{{{SERVICECUSTOMNOTES}}}</td>
|
||||
</tr>
|
||||
{{/SERVICECUSTOMNOTES}}
|
||||
{{{GRAPH_CODE}}}
|
||||
{{> foot_html}}
|
@ -7,11 +7,21 @@ State: {{LASTSERVICESTATE}} -> {{SERVICESTATE}} ({{NOTIFICATIONTYPE}}) since
|
||||
Output: {{SERVICEOUTPUT}}
|
||||
Perfdata: {{SERVICEPERFDATA}}
|
||||
{{LONGSERVICEOUTPUT}}
|
||||
{{#NOTIFICATIONCOMMENT}}
|
||||
|
||||
{{#SERVICENOTESURL}}More Info: {{SERVICENOTESURL}}
|
||||
|
||||
{{/SERVICENOTESURL}}
|
||||
Comment by {{NOTIFICATIONAUTHORALIAS}} ({{NOTIFICATIONAUTHORNAME}}):
|
||||
{{#NOTIFICATIONCOMMENT}}Comment by {{NOTIFICATIONAUTHORALIAS}} ({{NOTIFICATIONAUTHORNAME}}):
|
||||
{{NOTIFICATIONCOMMENT}}
|
||||
|
||||
{{/NOTIFICATIONCOMMENT}}
|
||||
{{#HOSTCUSTOMNOTES}}
|
||||
Custom Host Notes:
|
||||
{{{HOSTCUSTOMNOTES}}}
|
||||
|
||||
{{/HOSTCUSTOMNOTES}}
|
||||
{{#SERVICECUSTOMNOTES}}
|
||||
Custom Service Notes:
|
||||
{{{SERVICECUSTOMNOTES}}}
|
||||
|
||||
{{/SERVICECUSTOMNOTES}}
|
Reference in New Issue
Block a user