source: Serveur/flashpolicyd/flashpolicyd-2.1/check_flashpolicyd.rb @ 2850

Last change on this file since 2850 was 2844, checked in by kent1, 10 years ago

Import des deux serveurs "Flash Policy Server"

File size: 1.5 KB
Line 
1#!/usr/bin/ruby
2#
3# == Synopsis
4# Simple nagios plugin to check the status of an Adobe Flash Policy
5# server
6#
7# == Usage
8# check_flashpolicy --host HOSTNAME [--timeout TIMEOUT ]
9#
10# --host HOSTNAME
11#   The server to check
12#
13# --timeout TIMEOUT
14#   How long to wait to complete the transaction before assuming its critical. Default 5 seconds
15#
16# --help
17#   Show this help
18#
19# == Author
20# R.I.Pienaar <rip@devco.net>
21
22require 'socket'
23require 'timeout'
24require 'getoptlong'
25
26opts = GetoptLong.new(
27        [ '--host', GetoptLong::REQUIRED_ARGUMENT],
28        [ '--timeout', '-t', GetoptLong::OPTIONAL_ARGUMENT],
29        [ '--help', '-h', GetoptLong::NO_ARGUMENT]
30)
31
32timeout = 5
33hostname = false
34
35def showhelp
36        begin
37                require 'rdoc/ri/ri_paths'
38                require 'rdoc/usage'
39                RDoc::usage
40        rescue Exception => e
41                puts("Install RDoc::usage or view the comments in the top of the script to get detailed help")
42        end
43end
44
45opts.each { |opt, arg|
46        case opt
47        when '--help'
48                showhelp
49                exit
50        when '--host'
51                hostname = arg
52        when '--timeout'
53                timeout = arg
54        end
55}
56
57unless hostname
58        showhelp
59        exit
60end
61
62starttime = Time.new
63
64begin
65        timeout(timeout.to_i) do
66                t = TCPSocket.new(hostname, "843")
67                t.print("<policy-file-request/>\000")
68
69                answer = t.gets()
70                if answer.match(/xml version=/)
71                        puts("OK: Got XML response in #{Time.new - starttime} seconds")
72                else
73                        raise("Got unexpected resonse: #{answer}")
74                end
75
76                t.close
77        end
78rescue Timeout::Error
79        puts("CRITICAL: #{timeout} seconds TIMEOUT exceeded");
80        exit(2)
81rescue Exception => e
82        puts("CRITICAL: Unexpeced exception: #{e.message}")
83        exit(2)
84end
85
86exit(0)
Note: See TracBrowser for help on using the repository browser.