From 1f12a41f4ec2ffa8d4bdbb6074d44b2a2cce53df Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Sat, 6 Jan 2024 07:12:48 +0100 Subject: [PATCH] remove monitor which requires obsoleted module perl-LWP-Parallel-UserAgent [release 1.2.0-3mamba;Mon Nov 19 2012] --- README.md | 8 ++ mon-1.2.0-Makefile.patch | 84 ++++++++++++++++ mon-bring-ha-down.alert | 5 + mon-bring-ha-up.alert | 7 ++ mon-initscript | 47 +++++++++ mon-lvs.alert | 38 +++++++ mon-squid.monitor | 211 +++++++++++++++++++++++++++++++++++++++ mon.spec | 172 +++++++++++++++++++++++++++++++ 8 files changed, 572 insertions(+) create mode 100644 mon-1.2.0-Makefile.patch create mode 100644 mon-bring-ha-down.alert create mode 100644 mon-bring-ha-up.alert create mode 100644 mon-initscript create mode 100644 mon-lvs.alert create mode 100644 mon-squid.monitor create mode 100644 mon.spec diff --git a/README.md b/README.md index e2cdf6a..dc68bcf 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # mon +mon is a general-purpose scheduler and alert management tool used for monitoring service availability and triggering alerts upon failure detection. +mon was designed to be open and extensible in the sense that it supports arbitrary monitoring facilities and alert methods via a common interface, all of which are easily implemented with programs in C, Perl, shell, etc., SNMP traps, and special mon traps. +mon views resource monitoring as two separate tasks: the testing of a condition, and triggering an action upon failure. mon was designed to implement the testing and action-taking tasks as separate, stand-alone programs. mon is fundamentally a scheduler which executes the monitors (each test a specific condition), and calls the appropriate alerts if the monitor fails. +The decision to invoke an alert is governed by logic which offers various "squelch" features and dependencies, all of which are configurable by the user. +Monitors and alerts are not a part of the core mon server, even though the distribution comes with a handful of them to get you started. +This means that if a new service needs monitoring, or if a new alert is necessary, the mon server does not need to be changed. +This makes mon easily extensible. + diff --git a/mon-1.2.0-Makefile.patch b/mon-1.2.0-Makefile.patch new file mode 100644 index 0000000..933229f --- /dev/null +++ b/mon-1.2.0-Makefile.patch @@ -0,0 +1,84 @@ +diff -Nru mon-1.2.0.orig/etc/mon.cf mon-1.2.0/etc/mon.cf +--- mon-1.2.0.orig/etc/mon.cf 1970-01-01 01:00:00.000000000 +0100 ++++ mon-1.2.0/etc/mon.cf 2009-01-01 18:59:39.000000000 +0100 +@@ -0,0 +1,24 @@ ++# ++# Example "mon.cf" configuration for "mon". ++# ++# see example.cf for sample usage ++# ++ ++# ++# global options ++# ++cfbasedir = /etc/mon ++alertdir = /usr/lib/mon/alert.d ++mondir = /usr/lib/mon/mon.d ++maxprocs = 20 ++histlength = 100 ++randstart = 60s ++ ++# ++# authentication types: ++# getpwnam standard Unix passwd, NOT for shadow passwords ++# shadow Unix shadow passwords (not implemented) ++# userfile "mon" user file ++# ++authtype = getpwnam ++ +diff -Nru mon-1.2.0.orig/Makefile mon-1.2.0/Makefile +--- mon-1.2.0.orig/Makefile 1970-01-01 01:00:00.000000000 +0100 ++++ mon-1.2.0/Makefile 2009-01-01 19:01:10.000000000 +0100 +@@ -0,0 +1,43 @@ ++# ++# $Id: Makefile 1.2 Sun, 24 Jun 2001 22:41:40 -0400 trockij $ ++# ++# compiles on Linux, Solaris 2.5, Solaris 2.6, and AIX Version 4.2 ++# ++CC = gcc ++CFLAGS = -O2 -Wall -g ++LDFLAGS = ++LDLIBS = ++# uncomment next line for Solaris ++# LDLIBS = -lnsl -lsocket ++ ++MONPATH=/usr/lib/mon ++DIALIN_MONITOR_REAL=$(MONPATH)/mon.d/dialin.monitor ++ ++DESTDIR= ++PROGS = ++MANDIR = /usr/share/man ++SYSCONFDIR = /etc ++INITRDDIR = $(SYSCONFDIR)/rc.d/init.d ++ ++all: $(PROGS) ++ ++clean: ++ rm -f $(PROGS) ++ ++install: ++ mkdir -p $(DESTDIR)$(MONPATH)/{state.d,alert.d,mon.d} ++ install state.d/* $(DESTDIR)$(MONPATH)/state.d ++ install alert.d/* $(DESTDIR)$(MONPATH)/alert.d ++ install mon.d/*.monitor $(DESTDIR)$(MONPATH)/mon.d ++ install -m 755 mon $(DESTDIR)$(MONPATH) ++ ++ mkdir -p $(DESTDIR)$(MANDIR)/{man1,man8} ++ install -m 644 doc/moncmd.1 doc/monshow.1 $(DESTDIR)$(MANDIR)/man1 ++ install -m 644 doc/mon.8 $(DESTDIR)$(MANDIR)/man8 ++ ++ mkdir -p $(DESTDIR)$(SYSCONFDIR)/mon ++ install -m 644 etc/* $(DESTDIR)$(SYSCONFDIR)/mon ++ ++ mkdir -p $(DESTDIR)$(INITRDDIR) ++ install -m 755 etc/S99mon $(DESTDIR)$(INITRDDIR)/mon ++ +diff -Nru mon-1.2.0.orig/mon.d/Makefile mon-1.2.0/mon.d/Makefile +--- mon-1.2.0.orig/mon.d/Makefile 2009-01-01 19:01:47.000000000 +0100 ++++ mon-1.2.0/mon.d/Makefile 2009-01-01 18:59:39.000000000 +0100 +@@ -31,4 +31,4 @@ + install: + install -d $(MONPATH)/mon.d + install rpc.monitor $(MONPATH)/mon.d/ +- install -g uucp -m 02555 dialin.monitor.wrap $(MONPATH)/mon.d/ ++ install -m 02555 dialin.monitor.wrap $(MONPATH)/mon.d/ diff --git a/mon-bring-ha-down.alert b/mon-bring-ha-down.alert new file mode 100644 index 0000000..b2aeb1e --- /dev/null +++ b/mon-bring-ha-down.alert @@ -0,0 +1,5 @@ +#!/bin/bash +# +# bring-ha-down.alert - Heartbeat alert for mon +# +/usr/lib/heartbeat/hb_standby diff --git a/mon-bring-ha-up.alert b/mon-bring-ha-up.alert new file mode 100644 index 0000000..508511a --- /dev/null +++ b/mon-bring-ha-up.alert @@ -0,0 +1,7 @@ +#!/bin/bash +# +# bring-ha-up.alert - Heartbeat alert for mon +# +# to be used for auto_failback +# +/usr/lib/heartbeat/hb_takeover diff --git a/mon-initscript b/mon-initscript new file mode 100644 index 0000000..cda8ebd --- /dev/null +++ b/mon-initscript @@ -0,0 +1,47 @@ +#!/bin/sh +# +# start/stop the mon server +# +# You probably want to set the path to include +# nothing but local filesystems. +# +# chkconfig: 2345 99 10 +# description: mon system monitoring daemon +# processname: mon +# config: /etc/mon/mon.cf +# pidfile: /var/run/mon.pid +# +PATH=/bin:/usr/bin:/sbin:/usr/sbin +export PATH + +# Source function library. +. /etc/rc.d/init.d/functions + +# See how we were called. +case "$1" in + start) + echo -n "Starting mon daemon: " + /usr/lib/mon/mon -f -c /etc/mon/mon.cf + evaluate_retval + echo + touch /var/lock/subsys/mon + ;; + stop) + echo -n "Stopping mon daemon: " + killproc mon + echo + rm -f /var/lock/subsys/mon + ;; + status) + status mon + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: mon {start|stop|status|restart}" + exit 1 +esac + +exit 0 diff --git a/mon-lvs.alert b/mon-lvs.alert new file mode 100644 index 0000000..8d396b8 --- /dev/null +++ b/mon-lvs.alert @@ -0,0 +1,38 @@ +#!/usr/bin/perl +# +# lvs.alert - Linux Virtual Server alert for mon +# +# It can be activated by mon to remove a real server when the +# service is down, or add the server when the service is up. +# +# +use Getopt::Std; +getopts ("s:g:h:t:l:P:V:R:W:F:u"); + +$ipvsadm = "/sbin/ipvsadm"; +$protocol = $opt_P; +$virtual_service = $opt_V; +$remote = $opt_R; + +if ($opt_u) { + $weight = $opt_W; + if ($opt_F eq "nat") { + $forwarding = "-m"; + } elsif ($opt_F eq "tun") { + $forwarding = "-i"; + } else { + $forwarding = "-g"; + } + + if ($protocol eq "tcp") { + system("$ipvsadm -a -t $virtual_service -r $remote -w $weight $forwarding"); + } else { + system("$ipvsadm -a -u $virtual_service -r $remote -w $weight $forwarding"); + } +} else { + if ($protocol eq "tcp") { + system("$ipvsadm -d -t $virtual_service -r $remote"); + } else { + system("$ipvsadm -d -u $virtual_service -r $remote"); + } +}; diff --git a/mon-squid.monitor b/mon-squid.monitor new file mode 100644 index 0000000..9f8468f --- /dev/null +++ b/mon-squid.monitor @@ -0,0 +1,211 @@ +#!/usr/bin/perl +# +# Use try to connect to a proxy server. +# For use with "mon". +# +# Modified by Silvan Calarco +# it just returns ok if the proxy server returns a 400 (page not found) error +# and defaults to port 3128 +# +# proxy.monitor [-p port] [-t secs] [-u url] [-a agent] [-o] host [host...] +# +# -p port TCP port to connect to (defaults to 3128) +# -t secs timeout, defaults to 30 +# -u url path to get, defaults to "/" +# -a agent User-Agent, default to "mon.d/proxy.monitor" +# -o omit http headers from healthy hosts +# +# Jon Meek +# American Cyanamid Company +# Princeton, NJ +# +# $Id: proxy.monitor 1.4 Sat, 30 Jun 2001 14:44:29 -0400 trockij $ +# +# Copyright (C) 1998, Jim Trocki +# +# 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 2 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, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +use Getopt::Std; +use English; +use Data::Dumper; + +sub httpGET; + +getopts ("p:t:u:a:o"); +$PORT = $opt_p || 3128; +$TIMEOUT = $opt_t || 30; +$URL = $opt_u || "/"; +$USERAGENT = $opt_a || "mon.d/squid.monitor"; + +my %good; +my %bad; + +exit 0 if (!@ARGV); + +foreach my $host (@ARGV) { + my $result = httpGET ($host, $PORT); + + if (!$result->{"ok"}) { + $bad{$host} = $result; + } else { + $good{$host} = $result; + } +} + +my $ret; + +if (keys %bad) { + $ret = 1; + print join (" ", sort keys %bad), "\n"; +} else { + $ret = 0; + print "\n"; +} + +foreach my $h (keys %bad) { + print "HOST $h: $bad{$h}->{error}\n"; + if ($bad{$h}->{"header"} ne "") { + print $bad{$h}->{"header"}, "\n"; + } + print "\n"; +} + +if (!$opt_o) +{ + foreach my $h (keys %good) { + print "HOST $h: ok\n"; + print $good{$h}->{"header"}, "\n"; + print "\n"; + } +} + +exit $ret; + + +sub httpGET { + use Socket; + use Sys::Hostname; + + my($Server, $Port) = @_; + my($ServerOK, $TheContent); + + $TheContent = ''; + + my $Path = $URL; + + my $result; + +############################################################### + eval { + local $SIG{ALRM} = sub { die "Timeout Alarm" }; + alarm $TIMEOUT; + + my $err = &OpenSocket($Server, $Port); # Open a connection to the server + + if ($err ne "") { # Failure to open the socket + $result = { + "ok" => 0, + "error" => $err, + "header" => undef, + }; + + return undef; + } + + print S "GET $Path HTTP/1.0\r\n"; + print S "Host: $Server\r\n"; + print S "User-Agent: $USERAGENT\r\n\r\n"; + + while ($in = ) { + $TheContent .= $in; # Store data for later processing + } + +# HTTP/1.1 200 OK + + if ($TheContent =~ /^HTTP\/([\d\.]+)\s+(200|30[12]|40[01])\b/) { + $ServerOK = 1; + } else { + $ServerOK = 0; + } + + close(S); + alarm 0; # Cancel the alarm + + }; + + my ($header) = ($TheContent =~ /^(.*?)\r?\n\r?\n/s); + + if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { + return { + "ok" => 0, + "error" => "timeout after $TIMEOUT seconds", + "header" => $header, + }; + } + + if ($result->{"error"} ne "") { + return $result; + } + + return { + "ok" => $ServerOK, + "header" => $header, + "error" => undef, + }; +} + +# +# Make a Berkeley socket connection between this program and a TCP port +# on another (or this) host. Port can be a number or a named service +# +# returns "" on success, or an error string on failure +# +sub OpenSocket { + my ($host, $port) = @_; + + my $proto = (getprotobyname('tcp'))[2]; + + return ("could not get protocol") if (!defined $proto); + + my $conn_port; + + if ($port =~ /^\d+$/) { + $conn_port = $port; + + } else { + $conn_port = (getservbyname($port, 'tcp'))[2]; + return ("could not getservbyname for $port") + if (!defined $conn_port); + } + + my $host_addr = (gethostbyname($host))[4]; + + return ("gethostbyname failure") + if (!defined $host_addr); + + my $that = sockaddr_in ($conn_port, $host_addr); + + if (!socket (S, &PF_INET, &SOCK_STREAM, $proto)) { + return ("socket: $!"); + } + + if (!connect (S, $that)) { + return ("connect: $!"); + } + + select(S); $| = 1; select(STDOUT); + + ""; +} diff --git a/mon.spec b/mon.spec new file mode 100644 index 0000000..4122bf7 --- /dev/null +++ b/mon.spec @@ -0,0 +1,172 @@ +%define moncgi_version 1.52 + +Name: mon +Version: 1.2.0 +Release: 3mamba +Summary: A scheduler and alert management tool used for monitoring service availability and triggering alerts upon failure detection +Group: System/Servers +Vendor: openmamba +Distribution: openmamba +Packager: Silvan Calarco +URL: http://www.kernel.org/pub/software/admin/mon/html/ +Source0: http://www.giano.lkams.kernel.org/pub/software/admin/mon/mon-%{version}.tar.bz2 +Source1: mon-initscript +Source2: mon-lvs.alert +Source3: mon-bring-ha-down.alert +Source4: mon-squid.monitor +Source5: http://www.kernel.org/pub/software/admin/mon/contrib/all-monitors.tar.gz +Source6: http://www.kernel.org/pub/software/admin/mon/contrib/all-alerts.tar.gz +Source7: http://www.kernel.org/pub/software/admin/mon/contrib/cgi-bin/mon.cgi/mon.cgi-%{moncgi_version}.tar.bz2 +Source8: mon-bring-ha-up.alert +Patch0: mon-1.2.0-Makefile.patch +License: GPL +## AUTOBUILDREQ-BEGIN +BuildRequires: glibc-devel +BuildRequires: libtirpc-devel +## AUTOBUILDREQ-END +BuildRoot: %{_tmppath}/%{name}-%{version}-root + +%description +mon is a general-purpose scheduler and alert management tool used for monitoring service availability and triggering alerts upon failure detection. +mon was designed to be open and extensible in the sense that it supports arbitrary monitoring facilities and alert methods via a common interface, all of which are easily implemented with programs in C, Perl, shell, etc., SNMP traps, and special mon traps. +mon views resource monitoring as two separate tasks: the testing of a condition, and triggering an action upon failure. mon was designed to implement the testing and action-taking tasks as separate, stand-alone programs. mon is fundamentally a scheduler which executes the monitors (each test a specific condition), and calls the appropriate alerts if the monitor fails. +The decision to invoke an alert is governed by logic which offers various "squelch" features and dependencies, all of which are configurable by the user. +Monitors and alerts are not a part of the core mon server, even though the distribution comes with a handful of them to get you started. +This means that if a new service needs monitoring, or if a new alert is necessary, the mon server does not need to be changed. +This makes mon easily extensible. + +%prep +%setup -q +%patch0 -p1 + +## fix an incorrect autodiscovered -Dopt dependency +#%define __perl_requires %{_builddir}/%{name}-%{version}/perl_requires.sh +#cat > perl_requires.sh << _EOF +##! /bin/sh +#%{_prefix}/lib/rpm/find-requires %{buildroot} %{_target_cpu} | grep -v "\-Dopt" +#_EOF +#chmod +x perl_requires.sh + +%build +%make -C mon.d LDLIBS="-ltirpc" + +%install +[ "%{buildroot}" != / ] && rm -rf %{buildroot} + +make -C mon.d install MONPATH=%{buildroot}%{_libdir}/mon +make install DESTDIR=%{buildroot} + +install -m 755 %{S:1} %{buildroot}%{_initrddir}/mon +install -m 755 %{S:2} %{buildroot}%{_libdir}/mon/alert.d/lvs.alert +install -m 755 %{S:3} %{buildroot}%{_libdir}/mon/alert.d/bring-ha-down.alert +install -m 755 %{S:4} %{buildroot}%{_libdir}/mon/mon.d/squid.monitor +install -m 755 %{S:8} %{buildroot}%{_libdir}/mon/alert.d/bring-ha-up.alert + +#sed -i "s|/usr/lib/sendmail|/usr/sbin/sendmail|" \ +# %{buildroot}%{_libdir}/mon/alert.d/* + +install -d %{buildroot}/var/log/mon + +rm -f %{buildroot}%{_sysconfdir}/mon/S99mon + +# install additional monitors and alerts +install -d %{buildroot}%{_libdir}/mon/examples + +pushd %{buildroot}%{_libdir}/mon/examples +tar xzf %{S:5} +tar xzf %{S:6} +sed -i "s|/usr/local/bin/perl|/usr/bin/perl|" \ + alerts/*/* monitors/*/* +# remove aim to avoid a perl dependency on aol perl module we don't want +rm -rf alerts/aim +popd + +%clean +[ "%{buildroot}" != / ] && rm -rf %{buildroot} + +%preun +if [ $1 -eq 0 ]; then +# erase + chkconfig mon + if [ $? -eq 0 ]; then + service mon stop + chkconfig --del mon + fi +fi +exit 0 + +%postun +if [ $1 -eq 1 ]; then +# upgrade + chkconfig mon + [ $? -eq 0 ] && service mon restart +fi +exit 0 + +%files +%defattr(-,root,root) +%dir %{_sysconfdir}/mon +%config(noreplace) %{_sysconfdir}/mon/* +%{_initrddir}/mon +%dir %{_libdir}/mon +%dir %{_libdir}/mon/mon.d +%{_libdir}/mon/mon.d/* +%dir %{_libdir}/mon/state.d +%{_libdir}/mon/state.d/* +%dir %{_libdir}/mon/alert.d +%{_libdir}/mon/alert.d/* +%{_libdir}/mon/mon +%dir %{_libdir}/mon/examples +%{_libdir}/mon/examples/* +%dir /var/log/mon +%{_mandir}/man1/* +%{_mandir}/man8/* + +%changelog +* Mon Nov 19 2012 Silvan Calarco 1.2.0-3mamba +- remove monitor which requires obsoleted module perl-LWP-Parallel-UserAgent + +* Fri Feb 05 2010 Silvan Calarco 1.2.0-2mamba +- rebuilt to remove executable requirements + +* Thu Jan 01 2009 Silvan Calarco 1.2.0-1mamba +- automatic update by autodist + +* Wed Oct 18 2006 Davide Madrisan 0.99.2-11qilnx +- specfile fixes and updates +- stop and restart the mon service using the 'service' command +- fixed %%preun script + +* Thu Nov 25 2004 Silvan Calarco 0.99.2-10qilnx +- added bring-ha-up.alert script to allow ha auto-failback + +* Fri Oct 15 2004 Silvan Calarco 0.99.2-9qilnx +- added additional monitors and alerts from ftp.kernel.org as examples + +* Thu Oct 14 2004 Silvan Calarco 0.99.2-8qilnx +- added squid.monitor script +- changed references to sendmail from /usr/lib/sendmail to /usr/sbin/sendmail + +* Thu Oct 14 2004 Silvan Calarco 0.99.2-7qilnx +- fix for previous fix + +* Thu Oct 14 2004 Silvan Calarco 0.99.2-6qilnx +- added bring-ha-down.alert script for use with heartbeat + +* Fri Jun 18 2004 Silvan Calarco 0.99.2-5qilnx +- really fixed initscript (oops I forgot to add the install line) +- don't overwrite config files on update +- create log directory (/var/log/mon) + +* Thu Jun 10 2004 Silvan Calarco 0.99.2-4qilnx +- added script lvs.alert +- fixed initscript restart + +* Mon May 03 2004 Silvan Calarco 0.99.2-3qilnx +- fixed requirement list (excluded "-Dopt") + +* Fri Apr 30 2004 Silvan Calarco 0.99.2-2qilnx +- fixed references tu /usr/local/bin/perl + +* Fri Apr 30 2004 Silvan Calarco 0.99.2-1qilnx +- first build