Skip to content

Commit

Permalink
This is a complete rewrite of the monitor to support WAMP v2 and the …
Browse files Browse the repository at this point in the history
…latest autobahn libraries.

Documentation and manifest updated as well.
  • Loading branch information
Camron Levanger committed May 19, 2015
1 parent b09c5a9 commit 3064f13
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 48 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
nagios_wss
==========

A Nagios Web Socket Monitoring Plugin
A Nagios WAMP V2 Web Socket Monitoring Plugin
-------------------------------------
###If you need WAMP V1 monitoring checkout my older releases (v1.0.0)

A Nagios NRPE script that allows you to monitor a web socket server using
the WAMP protocol. While it is fairly easy with Nagios to monitor whether
the *WAMP V2* protocol. While it is fairly easy with Nagios to monitor whether
or not your server proccess is running, unfortunately that can't tell us
if that server is available and accepting connections.

Expand All @@ -32,14 +33,13 @@ and finally set proper permissions.
git clone git@github.com:camronlevanger/nagios-wss.git
cd nagios-wss
pip install -r requirements.txt
chmod +x check_wss_conn.py

Then restart the NRPE service, on Ubuntu that looks like:

service nagios-nrpe-server restart

####Install Using Pip
Coming Soon
Coming Soon(er or later)

###Add nagios-wss Command to NRPE Client
Now we need to edit our nrpe.cfg file and add our new plugin command.
Expand All @@ -59,9 +59,11 @@ To pass args to the command make sure you set in nrpe.cfg

dont_blame_nrpe=1

And then the host arg is
###Important arguments:

-H host_uri
+ -H host_uri | The url you use to connect to the socket server - This defaults to wss://localhost:8080/ws
+ -R realm | The WAMP realm your server is listening on - defaults to realm1
+ -T topic | The name of the topic you want the monitor to attempt subscribing to - defaults to notifications.1

###Add nagios-wss to Nagios Checks on Your Nagios Monitoring Server
Define a new service for nagios-wss
Expand Down
92 changes: 57 additions & 35 deletions check_wss_conn.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,76 +1,98 @@
#!/usr/bin/python
import sys
import os
import traceback
import argparse

from twisted.python import log
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks

from autobahn.websocket import connectWS
from autobahn.wamp import WampClientFactory
from autobahn.wamp import WampClientProtocol
from autobahn.twisted.wamp import ApplicationSession

exit_code = 3
exit_message = 'UNKNOWN - Unable to get info for socket connections'
topic = 'notifications.1'

class NagiosMonitor(WampClientProtocol):

def onOpen(self):
global exit_code
global exit_message
exit_code = 1
exit_message = 'Warning - Welcome message recieved, but no session'
class Component(ApplicationSession):

def onSessionOpen(self):
global exit_code
global exit_message
exit_code = 0
exit_message = 'OK - Socket session fully established'
self.dropConnection(self)
reactor.stop()
"""
An application component that subscribes and receives events,
and stop after having received 5 events.
"""

def clientConnectionFailed(self, connector, reason):
@inlineCallbacks
def onJoin(self, details):
global exit_code
global exit_message
exit_code = 2
exit_message = "CRITICAL - Unable to connect to socket server"
reactor.stop()

global topic
exit_code = 1
exit_message = 'Warning - Connected, but no subscription made'

def on_event(msg):
print("Got event: {}".format(msg))

try:
yield self.subscribe(on_event, topic)
exit_code = 0
exit_message = 'OK - Socket session fully established'
reactor.stop()
except Exception:
exit_code = 1
exit_message = 'Warning - Connected, but no subscription made'

def onLeave(self, details):
"""
There is a bug in authobahn.wamp.protocol.py that always calls
disconnect() even if there is no longer a transport, so let's just
override it. This way Nagios doesn't get 'Unhandled Error' as the
exit message.
"""
if self._transport:
self.disconnect()

if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='A Nagios plugin to monitor WAMP servers'
)

parser = argparse.ArgumentParser(description='A Nagios plugin to monitor WAMP servers')
parser.add_argument('-H', '--host')
parser.add_argument('-R', '--realm')
parser.add_argument('-T', '--topic')
parser.add_argument('--debug', action="store_true")
parser.add_argument('-t', '--timeout', type=int)
args = parser.parse_args()

host = 'wss://localhost:8080'
if args.host != None:
host = 'wss://localhost:8080/ws'
if args.host is not None:
host = args.host

realm = 'realm1'
if args.realm is not None:
realm = args.realm

topic = 'notifications.1'
if args.topic is not None:
topic = args.topic

debug = False
if args.debug != None:
if args.debug is not None:
debug = args.debug

timeout = 30
if args.timeout != None:
if args.timeout is not None:
timeout = args.timeout


try:
if debug:
log.startLogging(sys.stdout)

factory = WampClientFactory(host, debugWamp=debug)
factory.protocol = NagiosMonitor
connectWS(factory, timeout = timeout)
reactor.run()
from autobahn.twisted.wamp import ApplicationRunner
runner = ApplicationRunner(host, realm)
runner.run(Component)
except KeyboardInterrupt:
print "Shutdown requested...exiting"
except Exception:
traceback.print_exc(file=sys.stdout)
exit_code = 2
exit_message = "CRITICAL - Unable to connect to socket server"

print exit_message
sys.exit(exit_code)
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Twisted==13.2.0
autobahn==0.6.4
pyOpenSSL==0.13.1
Twisted==15.1.0
autobahn[twisted]==0.10.2
pyOpenSSL==0.15.1
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# http://packaging.python.org/en/latest/tutorial.html#version
version='0.1.0',
version='2.0.0',

description='Monitor WAMP servers with Nagios.',
description='Monitor WAMP V2 servers with Nagios.',
long_description=long_description,

# The project's main homepage.
Expand All @@ -35,7 +35,7 @@
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',
'Development Status :: 3 - Alpha',

# Indicate who your project is intended for
'Intended Audience :: Developers',
Expand All @@ -62,7 +62,7 @@
# project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/technical.html#install-requires-vs-requirements-files
install_requires=['Twisted==13.2.0', 'autobahn==0.6.4', 'pyOpenSSL==0.13.1'],
install_requires=['Twisted==15.1.0', 'autobahn[twisted]==0.10.2', 'pyOpenSSL==0.15.1'],

# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
Expand Down

0 comments on commit 3064f13

Please sign in to comment.