Skip to content

Commit

Permalink
Update with new versions of bootstrap/jQuery and update python client.
Browse files Browse the repository at this point in the history
  • Loading branch information
jomann09 committed Feb 12, 2021
1 parent 3c39a6b commit 6a940e1
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 24 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
2.0.4 - ??-??-2020
2.0.4 - 02/12/2020
------------------
- Updated Bootstrap to version 4.6.0
- Updated jQuery to version 3.5.1 to fix CVEs
- Updated send_nrdp.py to Python 3, old Python 2 plugin is check_nrdp_py2.py and unsupported due to EOL
- Fixed send_nrdp.php doesnt work in case plugin output contains $delim char (#50) (ccztux)
- Fixed send_nrdp.php produces handle_api_error(msg=BAD XML) (#52) (ccztux)
- Fixed send_nrdp.php is always returning 0 (#54) (ccztux)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Download the latest tarball and extract to start the install:

```
cd /tmp
wget https://github.com/NagiosEnterprises/nrdp/archive/2.0.3.tar.gz
tar xvf 2.0.3.tar.gz
wget https://github.com/NagiosEnterprises/nrdp/archive/2.0.4.tar.gz
tar xvf 2.0.4.tar.gz
cd nrdp-*
```

Expand Down
205 changes: 205 additions & 0 deletions clients/send_nrdp_py2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#!/usr/bin/env python

##############################################################################
#
#
# send_nrdp.py - Send host/service checkresults to NRDP with XML
#
#
# Copyright (c) 2008-2020 - Nagios Enterprises, LLC. All rights reserved.
# Originally Authored: Scott Wilkerson (nagios@nagios.org)
#
# License: GNU General Public License version 3
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#############################################################################
#
# 2017-09-22 Troy Lea aka BOX293
# - Fixed setup function that was not working for piped results
# as the xml string was missing "</checkresults>"
# - Fixed setup function that was not working with arguments when
# run as a cron job or if being used as a nagios command like
# obsessive compulsive ... "if not sys.stdin.isatty():" was the
# reason why.
#
# 2017-09-25 Troy Lea aka BOX293
# - Added file argument to allow XML results to be read from file
# - Replaced optparse with argparse so help text can include newline
# characters, allowing for better formatting.
#
# 2017-09-26 Troy Lea aka BOX293
# - Made sure url ends with a / before posting
#
#############################################################################


import argparse, sys, urllib, cgi
from xml.dom.minidom import parseString

class send_nrdp:
def run(self):
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)

parser.add_argument('-u', '--url', action="store",
dest="url", help="\
** REQUIRED ** The URL used to access the remote NRDP agent.")
parser.add_argument('-t', '--token', action="store",
dest="token", help="\
** REQUIRED ** The authentication token used to access the\n\
remote NRDP agent.")
parser.add_argument('-H', '--hostname', action="store",
dest="hostname", help="\
The name of the host associated with the passive host/service\n\
check result.")
parser.add_argument('-s', '--service', action="store",
dest="service", help="\
For service checks, the name of the service associated with the\n\
passive check result.")
parser.add_argument('-S', '--state', action="store",
dest="state", help="\
An integer indicating the current state of the host or service.")
parser.add_argument('-o', '--output', action="store",
dest="output", help="\
Text output to be sent as the passive check result.\n\
Newlines should be encoded with encoded newlines (\\n).")
parser.add_argument('-f', '--file', action="store",
dest="file", help="\
This file will be sent to the NRDP server specified in -u\n\
The file should be an XML file in the following format:\n\
##################################################\n\
<?xml version='1.0'?>\n\
<checkresults>\n\
<checkresult type=\"host\" checktype=\"1\">\n\
<hostname>YOUR_HOSTNAME</hostname>\n\
<state>0</state>\n\
<output>OK|perfdata=1.00;5;10;0</output>\n\
</checkresult>\n\
<checkresult type=\"service\" checktype=\"1\">\n\
<hostname>YOUR_HOSTNAME</hostname>\n\
<servicename>YOUR_SERVICENAME</servicename>\n\
<state>0</state>\n\
<output>OK|perfdata=1.00;5;10;0</output>\n\
</checkresult>\n\
</checkresults>\n\
##################################################")
parser.add_argument('-d', '--delim', action="store",
dest="delim", help="\
With only the required parameters send_nrdp.py is capable of\n\
processing data piped to it either from a file or other process.\n\
By default, we use t (\\t) as the delimiter however this may be\n\
specified with the -d option data should be in the following\n\
formats of one entry per line:\n\
printf \"<hostname>\\t<state>\\t<output>\\n\"\n\
printf \"<hostname>\\t<service>\\t<state>\\t<output>\\n\"\n")
parser.add_argument('-c', '--checktype', action="store",
dest="checktype", help="1 for passive 0 for active")

options = parser.parse_args()

if not options.url:
parser.error('You must specify a url.')
if not options.token:
parser.error('You must specify a token.')
try:
self.setup(options)
sys.exit()
except Exception, e:
sys.exit(e)

def getText(self, nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)

def post_data(self, url, token, xml):
# Make sure URL ends with a /
if not url.endswith('/'):
url += '/'

params = urllib.urlencode({'token': token.strip(), 'cmd': 'submitcheck', 'xml': xml});
opener = urllib.FancyURLopener()
try:
f = opener.open(url, params)
result = parseString(f.read())
except Exception, e:
print "Cannot connect to url."
# TODO add directory option
sys.exit(e)
if self.getText(result.getElementsByTagName("status")[0].childNodes) == "0":
sys.exit()
else:
print "ERROR - NRDP Returned: "+self.getText(result.getElementsByTagName("message")[0].childNodes)
sys.exit(1)

def setup(self, options):
if not options.delim:
options.delim = "\t"
if not options.checktype:
options.checktype = "1"

# If only url and token have been provided then it is assumed that data is being piped
if not options.hostname and not options.state and not options.file:
xml="<?xml version='1.0'?>\n<checkresults>\n";
for line in sys.stdin.readlines():
parts = line.split(options.delim)
if len(parts) == 4:
xml += "<checkresult type='service' checktype='"+options.checktype+"'>"
xml += "<hostname>"+cgi.escape(parts[0],True)+"</hostname>"
xml += "<servicename>"+cgi.escape(parts[1],True)+"</servicename>"
xml += "<state>"+parts[2]+"</state>"
xml += "<output>"+cgi.escape(parts[3],True)+"</output>"
xml += "</checkresult>"
if len(parts) == 3:
xml += "<checkresult type='host' checktype='"+options.checktype+"'>"
xml += "<hostname>"+cgi.escape(parts[0],True)+"</hostname>"
xml += "<state>"+parts[1]+"</state>"
xml += "<output>"+cgi.escape(parts[2],True)+"</output>"
xml += "</checkresult>"
xml += "</checkresults>"

elif options.hostname and options.state:
xml="<?xml version='1.0'?>\n<checkresults>\n";
if options.service:
xml += "<checkresult type='service' checktype='"+options.checktype+"'>"
xml += "<hostname>"+cgi.escape(options.hostname,True)+"</hostname>"
xml += "<servicename>"+cgi.escape(options.service,True)+"</servicename>"
xml += "<state>"+options.state+"</state>"
xml += "<output>"+cgi.escape(options.output,True)+"</output>"
xml += "</checkresult>"
else:
xml += "<checkresult type='host' checktype='"+options.checktype+"'>"
xml += "<hostname>"+cgi.escape(options.hostname,True)+"</hostname>"
xml += "<state>"+options.state+"</state>"
xml += "<output>"+cgi.escape(options.output,True)+"</output>"
xml += "</checkresult>"
xml += "</checkresults>"

elif options.file:
try:
file_handle = open(options.file, 'r')
except Exception, e:
print "Error opening file '"+options.file+"'"
sys.exit(e)
else:
xml = file_handle.read()
file_handle.close()

self.post_data(options.url, options.token, xml)

if __name__ == "__main__":
send_nrdp().run()
6 changes: 6 additions & 0 deletions server/includes/bootstrap-4.6.0.bundle.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions server/includes/bootstrap-4.6.0.min.css

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions server/includes/bootstrap.bundle.min.js

This file was deleted.

6 changes: 0 additions & 6 deletions server/includes/bootstrap.min.css

This file was deleted.

2 changes: 1 addition & 1 deletion server/includes/constants.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

// PRODUCT INFO
define("PRODUCT_NAME", "nrdp");
define("PRODUCT_VERSION", "2.0.3");
define("PRODUCT_VERSION", "2.0.4");

// ERROR STRINGS
define("ERROR_CAPABILITY_NOT_ENABLED","NOT ENABLED");
Expand Down
4 changes: 0 additions & 4 deletions server/includes/jquery-3.2.1.min.js

This file was deleted.

2 changes: 2 additions & 0 deletions server/includes/jquery-3.5.1.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ function display_form()
<html>
<head>
<title>Nagios Remote Data Processor</title>
<script type="text/javascript" src="includes/jquery-3.2.1.min.js"></script>
<link href="includes/bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript" src="includes/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="includes/jquery-3.5.1.min.js"></script>
<link href="includes/bootstrap-4.6.0.min.css" rel="stylesheet" />
<script type="text/javascript" src="includes/bootstrap-4.6.0.bundle.min.js"></script>
<style>
body {
margin: 2em 0;
Expand All @@ -181,7 +181,7 @@ function display_form()

function build_alert(cssclass, msg) {

var $alert = $("<div class=\"alert alert-" + cssclass + " form-control-sm\">" + msg + "</div>");
var $alert = $("<div class=\"alert alert-" + cssclass + "\">" + msg + "</div>");
$(".messages").html($alert);
return $alert;
}
Expand Down

0 comments on commit 6a940e1

Please sign in to comment.