-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from iLert/feature/python3-support
Feature/python3 support
- Loading branch information
Showing
8 changed files
with
308 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/bin/bash | ||
# iLert Check_MK Plugin | ||
|
||
COMMAND="/usr/local/bin/ilert_nagios.py" | ||
COMMAND="python3 /usr/local/bin/ilert_nagios.py" | ||
|
||
$COMMAND --mode save --apikey $NOTIFY_PARAMETER_1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,24 @@ | |
|
||
# iLert Nagios/Icinga/Check_MK Plugin | ||
# | ||
# Copyright (c) 2013-2021, iLert GmbH. <[email protected]> | ||
# Copyright (c) 2013-2022, iLert GmbH. <[email protected]> | ||
# All rights reserved. | ||
|
||
|
||
import os | ||
import syslog | ||
import fcntl | ||
import urllib2 | ||
from urllib2 import HTTPError | ||
from urllib2 import URLError | ||
import urllib.request | ||
from urllib.request import HTTPError | ||
from urllib.error import URLError | ||
import uuid | ||
import ssl | ||
from xml.sax.saxutils import escape | ||
from xml.sax.saxutils import quoteattr | ||
import argparse | ||
import io | ||
|
||
PLUGIN_VERSION = "1.6" | ||
PLUGIN_VERSION = "1.7" | ||
|
||
|
||
def persist_event(api_key, directory, payload): | ||
|
@@ -72,12 +72,12 @@ def flush(endpoint, directory, port, insecure): | |
|
||
# populate list of event files sorted by creation date | ||
events = [os.path.join(directory, f) for f in os.listdir(directory)] | ||
events = filter(lambda x: x.endswith(".ilert"), events) | ||
events.sort(key=lambda x: os.path.getmtime(x)) | ||
events = list(filter(lambda x: x.endswith(".ilert"), events)) | ||
events = sorted(events, key=lambda x: os.path.getmtime(x)) | ||
|
||
for event in events: | ||
try: | ||
with open(event, 'r') as f: | ||
with open(event, 'r', encoding='utf-8') as f: | ||
xml_doc = f.read() | ||
except IOError: | ||
continue | ||
|
@@ -89,8 +89,9 @@ def flush(endpoint, directory, port, insecure): | |
if insecure == True: | ||
ctx.check_hostname = False | ||
ctx.verify_mode = ssl.CERT_NONE | ||
req = urllib2.Request(url, xml_doc, headers) | ||
urllib2.urlopen(req, timeout=60, context=ctx) | ||
data = xml_doc.encode('utf-8') | ||
req = urllib.request.Request(url, data, headers) | ||
urllib.request.urlopen(req, timeout=60, context=ctx) | ||
except HTTPError as e: | ||
if e.code == 429: | ||
syslog.syslog(syslog.LOG_WARNING, "too many requests, will try later. Server response: %s" % e.read()) | ||
|
@@ -117,7 +118,8 @@ def create_xml(apikey, payload): | |
xml_doc += "<event><apiKey>%s</apiKey><payload>" % apikey | ||
|
||
for entry in payload: | ||
xml_doc += "<entry key=%s>%s</entry>" % (quoteattr(entry), unicode(escape(payload[entry]), encoding='utf-8', errors='ignore')) | ||
byte_str = escape(payload[entry]) | ||
xml_doc += "<entry key=%s>%s</entry>" % (quoteattr(entry), escape(payload[entry])) | ||
|
||
# XML document end tag | ||
xml_doc += "</payload></event>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# iLert Check_MK Plugin | ||
|
||
COMMAND="/usr/local/bin/ilert_nagios.py" | ||
|
||
$COMMAND --mode save --apikey $NOTIFY_PARAMETER_1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
object User "ilert" { | ||
display_name = "iLert" | ||
groups = [ "icingaadmins" ] | ||
states = [ OK, Warning, Critical, Unknown] | ||
types = [ Problem, Recovery, Acknowledgement ] | ||
vars.additional_notes = "This user maps to an alert source in iLert." | ||
pager = "<YOUR API KEY>" | ||
} | ||
|
||
object NotificationCommand "ilert-notification" { | ||
import "plugin-notification-command" | ||
|
||
command = "/usr/local/bin/ilert_nagios.py -m save" | ||
|
||
env = { | ||
ICINGA_CONTACTPAGER = "$user.pager$" | ||
ICINGA_NOTIFICATIONTYPE = "$notification.type$" | ||
ICINGA_LONGDATETIME = "$icinga.long_date_time$" | ||
ICINGA_HOSTADDRESS = "$address$" | ||
ICINGA_HOSTNAME = "$host.name$" | ||
ICINGA_HOSTALIAS = "$host.display_name$" | ||
ICINGA_HOSTSTATE = "$host.state$" | ||
ICINGA_HOSTOUTPUT="$host.output$" | ||
ICINGA_SERVICESTATE = "$service.state$" | ||
ICINGA_SERVICEDESC = "$service.name$" | ||
ICINGA_SERVICEDISPLAYNAME = "$service.display_name$" | ||
ICINGA_SERVICEOUTPUT = "$service.output$" | ||
ICINGA_NOTIFICATIONCOMMENT = "$notification.comment$" | ||
} | ||
} | ||
|
||
apply Notification "ilert-host-notification" to Host { | ||
command = "ilert-notification" | ||
states = [ Up, Down ] | ||
types = [ Problem, Acknowledgement, Recovery ] | ||
period = "24x7" | ||
users = [ "ilert" ] | ||
|
||
assign where host.vars.notification.enable_ilert == true | ||
} | ||
|
||
apply Notification "ilert-service-notification" to Service { | ||
command = "ilert-notification" | ||
states = [ OK, Warning, Critical, Unknown ] | ||
types = [ Problem, Acknowledgement, Recovery ] | ||
period = "24x7" | ||
users = [ "ilert" ] | ||
|
||
assign where service.vars.notification.enable_ilert == true | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
############################################################################################ | ||
# NOTE: use this file if you're using Nagios or Icinga 1.x. If you're using Icinga 2.x, # | ||
# use ilert_icinga2.conf instead. # | ||
############################################################################################ | ||
|
||
define contact { | ||
contact_name ilert | ||
alias iLert | ||
service_notification_period 24x7 | ||
host_notification_period 24x7 | ||
service_notification_options w,u,c,r | ||
host_notification_options d,r | ||
service_notification_commands notify-ilert | ||
host_notification_commands notify-ilert | ||
pager <YOUR API KEY> | ||
} | ||
|
||
define command { | ||
command_name notify-ilert | ||
command_line /usr/local/bin/ilert_nagios.py -m save | ||
} | ||
|
||
# | ||
# Use the following command definition if the configuration option enable_environment_macros is set to 0. | ||
# | ||
|
||
#define command { | ||
# command_name notify-ilert | ||
# command_line /usr/local/bin/ilert_nagios.py -m save CONTACTPAGER="$CONTACTPAGER$" NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" LONGDATETIME="$LONGDATETIME$" HOSTADDRESS="$HOSTADDRESS$" HOSTNAME="$HOSTNAME$" HOSTSTATE="$HOSTSTATE$" HOSTOUTPUT="$HOSTOUTPUT$" HOSTALIAS="$HOSTALIAS$" SERVICEDESC="$SERVICEDESC$" SERVICESTATE="$SERVICESTATE$" SERVICEOUTPUT="$SERVICEOUTPUT$" | ||
#} | ||
|
Oops, something went wrong.