#!/usr/bin/ruby # # NAME # ---- # - xymon_m0n0CFG.rb # # DESCRIPTION # ----------- # - A Xymon external client script to poll the index.php page # of m0n0wall firewalls and report back the m0n0wall's Version, # Platform, Uptime, Last Config Change, and Notes fields to a # Xymon Monitoring Server # # FEATURES # -------- # - In addition to simply reporting back some basic information from # a m0n0wall's index.php page, this script also has the following # features: # # 1. Signal a yellow alert for a m0n0wall that has been UP for less # than 24 hours # 2. Signal a yellow alert for a m0n0wall that has its configuration # changed. # # - The most current version of this script may be # found at http://www.revpol.com/xymon_m0n0CFG_script # # - Instructions to integrate the output of this script to be monitored # by a Xymon server may also be found at the above URL # # ADDITIONAL FILES # ---------------- # - Along with xymon_m0n0CFG.rb there are three other files: # # 1. m0n0walls.cfg - This is the config file that lists each of the m0n0walls # by their FQDN as listed in bb-hosts, along with their # last known config change. # # The next two files are required if you plan on using the "Click to Remedy" # link on the m0n0CFG status page when a change in a m0n0wall's configuration # is detected. # # 2. ext_xymon_m0n0CFG.sh - This file goes into the ~xymon/cgi-secure # directory. It is what the "Click to Remedy" link # points to, and it just sources the # ~xymon/server/etc/hobbitserver.cfg file and then # calls the ~xymon/server/bin/ext_xymon_m0n0CFG.rb # script # 3. ext_xymon_m0n0CFG.rb - This file goes into the ~xymon/server/bin directory # It is the script that updates the m0n0walls.cfg file # by replacing the last_cfg timestamp for the m0n0wall # in question # # - If you find this script useful, we'd love to know. Send us an email! # # Authors # ------- # William A. Arlofski, Darrik Mazey # Reverse Polarity, LLC # 860-824-2433 Office # http://www.revpol.com/ # # HISTORY # ------- # - 20090619 - Initial limited version using bash # - 20100614 - Major overhauls, including complete re-write in ruby # - 20100720 - More major changes including the addition of m0n0CFGlogin # option with the user:pass:proto:port variables added to the # bb-hosts file, and removed from the m0n0walls.cfg file # ############################################################################### # # Copyright (C) 2010 - William A. Arlofski - waa-at-revpol-dot-com # - Darrik Mazey - darrik-at-darmasoft-dot-com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # or visit http://www.gnu.org/licenses/gpl.txt # ############################################################################### # Ruby Modules Required # --------------------- # For parsing the yaml config file # and For URL escaping # -------------------------------- require "yaml" require "cgi" # Set up some local binaries # -------------------------- date = ENV['DATE'] wget = "/usr/bin/wget" # Set up some Xymon variables # --------------------------- bb = ENV['BB'] bbdisp = ENV['BBDISP'] bbhome = ENV['BBHOME'] column = "m0n0CFG" bbhosts = "#{bbhome}/etc/bb-hosts" bbhostgrep = "#{bbhome}/bin/bbhostgrep" cfg_file = "#{bbhome}/etc/m0n0walls.cfg" # Print the "Click to Remedy" link that calls the # CGI scripts to automatically update the "last_cfg" # variable in the m0n0wall.cfg file with the Last Config # Change date/time reported by the m0n0wall # ------------------------------------------------------ allow_cgi_fix = "1" # Enable debugging output to log file? # This will generate a LOT of information # So you may wish to use it sparingly # --------------------------------------- debug = "1" # End config variables # -------------------- # Get the list of hosts that have # the "m0n0CFG" test set in bb-hosts # The "*" gets us both the m0n0CFG and # the m0n0CFGlogin:user:pass:proto:port # information # ------------------------------------- host_lines = %x{#{bbhostgrep} #{column}"*"} hosts = host_lines.split(/\n/) # Loop through list of m0n0walls # ------------------------------ hosts.each do |thishost| # Get the current time # -------------------- date_cmd = %Q{#{date}} rightnow = %x{#{date_cmd}} rightnow.chomp! # Set default color and msg # ------------------------- msg = "" color = "green" # Get the host and its IP # from the bb-hosts file # ----------------------- host_line_parts = thishost.split(' ') hostip = host_line_parts[0] hostkey = host_line_parts[1] # Read bb-hosts file and get the m0n0CFGlogin # settings for this host. The settings are in # the following format: # m0n0CFGlogin=user:pass:proto:port # ------------------------------------------- loginkey = host_line_parts[4] login_key_parts = loginkey.split(':') user = login_key_parts[1] pass = login_key_parts[2] proto = login_key_parts[3] port = login_key_parts[4] # Read the m0n0walls.cfg file and # get the last_cfg for this host # ------------------------------- config = YAML.load_file cfg_file host_config = config[hostkey] host = hostkey last_cfg = host_config['last_config'] # Get index.php page from m0n0wall host # -------------------------------------- m0n0wall_system_cmd = %Q{#{wget} -q --no-check-certificate --timeout=5 --tries=2 --user=#{user} --password=#{pass} -O - #{proto}://#{hostip}:#{port}/} m0n0wall_system = %x{#{m0n0wall_system_cmd}} # And strip out the DOS carriage returns # *NOTE* # That is a CTRL-M, not a carat and Capital M # ------------------------------------------- m0n0wall_system.gsub!(/ /, '') # Did the wget command timeout or fail to return any data? # -------------------------------------------------------- if m0n0wall_system.nil? || m0n0wall_system == "" color = "yellow" version = "*unknown*" platform = "*unknown*" cur_uptime = "*unknown*" cur_cfg = "*unknown*" notes = "*unknown*" msg = "&#{color} Timeout or no data returned from #{host} \(#{hostip}\)" else # ------------------------------------- # We seem to have gotten good data from # the m0n0wall so assign the variables # ------------------------------------- # Get Notes from