Add check_openvpn
This commit is contained in:
		
							parent
							
								
									8a8d12bd24
								
							
						
					
					
						commit
						e3da64769f
					
				
					 5 changed files with 123 additions and 0 deletions
				
			
		
							
								
								
									
										4
									
								
								check_openvpn/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								check_openvpn/Makefile
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
#/usr/bin/make -f
 | 
			
		||||
 | 
			
		||||
include ../common.mk
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										86
									
								
								check_openvpn/check_openvpn
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								check_openvpn/check_openvpn
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,86 @@
 | 
			
		|||
#! /usr/bin/python
 | 
			
		||||
 | 
			
		||||
# Check if an OpenVPN server runs on a given UDP port.
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2013 Roland Wolters, credativ GmbH
 | 
			
		||||
#
 | 
			
		||||
# Version 20130904
 | 
			
		||||
#
 | 
			
		||||
# Permission is hereby granted, free of charge, to any person obtaining
 | 
			
		||||
# a copy of this software and associated documentation files (the
 | 
			
		||||
# "Software"), to deal in the Software without restriction, including
 | 
			
		||||
# without limitation the rights to use, copy, modify, merge, publish,
 | 
			
		||||
# distribute, sublicense, and/or sell copies of the Software, and to
 | 
			
		||||
# permit persons to whom the Software is furnished to do so, subject to
 | 
			
		||||
# the following conditions:
 | 
			
		||||
#
 | 
			
		||||
# The above copyright notice and this permission notice shall be
 | 
			
		||||
# included in all copies or substantial portions of the Software.
 | 
			
		||||
#
 | 
			
		||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 | 
			
		||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 | 
			
		||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 | 
			
		||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 | 
			
		||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 | 
			
		||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 | 
			
		||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import sys
 | 
			
		||||
import socket
 | 
			
		||||
import argparse
 | 
			
		||||
import binascii
 | 
			
		||||
 | 
			
		||||
def ok(msg):
 | 
			
		||||
    print "OK: %s" % msg
 | 
			
		||||
    sys.exit(0)
 | 
			
		||||
 | 
			
		||||
def critical(msg):
 | 
			
		||||
    print "CRIT: %s" % msg
 | 
			
		||||
    sys.exit(2)
 | 
			
		||||
 | 
			
		||||
def checkserver(host,port,proto):
 | 
			
		||||
    byte_stream = "\x38\x01\x00\x00\x00\x00\x00\x00\x00"
 | 
			
		||||
 | 
			
		||||
    if proto:
 | 
			
		||||
        ovpn_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 | 
			
		||||
    else:
 | 
			
		||||
        ovpn_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 | 
			
		||||
 | 
			
		||||
    ovpn_sock.settimeout(5)
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        ovpn_sock.connect((host, port))
 | 
			
		||||
        ovpn_sock.sendto(byte_stream, (host, port))
 | 
			
		||||
        data, addr = ovpn_sock.recvfrom(1024) # buffer size is 1024 bytes
 | 
			
		||||
        reply = binascii.hexlify(data)
 | 
			
		||||
        if proto:
 | 
			
		||||
            ok("OpenVPN tcp port reachable.")
 | 
			
		||||
        else:
 | 
			
		||||
            ok("OpenVPN server response (hex): %s" % reply)
 | 
			
		||||
    except socket.timeout:
 | 
			
		||||
        critical("Request timed out")
 | 
			
		||||
        ovpn_sock.close()
 | 
			
		||||
    except (socket.error, Exception):
 | 
			
		||||
        critical("OpenVPN server not responding")
 | 
			
		||||
        ovpn_sock.close()
 | 
			
		||||
 | 
			
		||||
    ovpn_sock.close()
 | 
			
		||||
    return data
 | 
			
		||||
 | 
			
		||||
def optionsparser():
 | 
			
		||||
    parser = argparse.ArgumentParser()
 | 
			
		||||
    parser.add_argument("-p","--port", help="set port number",
 | 
			
		||||
    type=int, dest="port", default="1194")
 | 
			
		||||
    parser.add_argument("-t","--tcp", help="use tcp instead of udp",
 | 
			
		||||
    action="store_true")
 | 
			
		||||
    parser.add_argument("host", type=str, help="the OpenVPN host name or ip")
 | 
			
		||||
    return parser.parse_args()
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
    arguments = optionsparser()
 | 
			
		||||
 | 
			
		||||
    data = checkserver(arguments.host,arguments.port,arguments.tcp)
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    main()
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								check_openvpn/check_openvpn.cfg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								check_openvpn/check_openvpn.cfg
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
# 'check_openvpn' command definition
 | 
			
		||||
define command {
 | 
			
		||||
        command_name    check_openvpn
 | 
			
		||||
        command_line    /usr/lib/monitoring-plugins/check_openvpn -p '$ARG1$' '$HOSTADDRESS$'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								check_openvpn/control
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								check_openvpn/control
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
Homepage: https://raw.github.com/liquidat/nagios-icinga-checks/master/check_openvpn
 | 
			
		||||
Watch: https://raw.github.com/liquidat/nagios-icinga-checks/master/check_openvpn Version\ ([0-9.]+)
 | 
			
		||||
Recommends: python-argparse
 | 
			
		||||
Version: 20130904
 | 
			
		||||
Uploaders: Jan Wagner <waja@cyconet.org>
 | 
			
		||||
Description: plugin to check if an OpenVPN server runs on a given port
 | 
			
		||||
							
								
								
									
										21
									
								
								check_openvpn/copyright
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								check_openvpn/copyright
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
Copyright 2013 Roland Wolters, credativ GmbH
 | 
			
		||||
 | 
			
		||||
License: MIT
 | 
			
		||||
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
in the Software without restriction, including without limitation the rights
 | 
			
		||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
furnished to do so, subject to the following conditions:
 | 
			
		||||
 | 
			
		||||
The above copyright notice and this permission notice shall be included in
 | 
			
		||||
all copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
THE SOFTWARE.
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue