Hi !
This is a quick (and probably dirty) patch to support clamav protocol
(see http://www.clamav.net).
Maybe, it should check more than a simple PING/PONG exchange (for
example a test with the Eicar-Test-Signature).
Hope it can help you.
Debrard Sébastien
Index: l.l
===================================================================
RCS file: /sources/monit/monit/l.l,v
retrieving revision 1.112
diff -u -8 -p -r1.112 l.l
--- l.l 19 Jul 2006 17:33:37 -0000 1.112
+++ l.l 25 Aug 2006 15:43:51 -0000
@@ -185,16 +185,17 @@ system { return SYSTEM; }
default { return DEFAULT; }
http { return HTTP; }
apache-status { return APACHESTATUS; }
ftp { return FTP; }
smtp { return SMTP; }
postfix-policy { return POSTFIXPOLICY; }
pop { return POP; }
imap { return IMAP; }
+clamav { return CLAMAV; }
dns { return DNS; }
mysql { return MYSQL; }
nntp { return NNTP; }
ntp3 { return NTP3; }
ssh { return SSH; }
dwp { return DWP; }
ldap2 { return LDAP2; }
ldap3 { return LDAP3; }
Index: monit.pod
===================================================================
RCS file: /sources/monit/monit/monit.pod,v
retrieving revision 1.192
diff -u -8 -p -r1.192 monit.pod
--- monit.pod 19 Jul 2006 19:36:56 -0000 1.192
+++ monit.pod 25 Aug 2006 15:43:51 -0000
@@ -1859,16 +1859,17 @@ B<proto(col):PROTO {protocols}>. Optiona
monit should speak when a connection is established. At the
moment monit knows how to speak:
I<APACHE-STATUS>
I<DNS>
I<DWP>
I<FTP>
I<HTTP>
I<IMAP>
+ I<CLAMAV>
I<LDAP2>
I<LDAP3>
I<MYSQL>
I<NNTP>
I<NTP3>
I<POP>
I<POSTFIX-POLICY>
I<RDATE>
@@ -3005,17 +3006,17 @@ I<if>, I<then>, I<else>, I<set>, I<daemo
I<syslog>, I<address>, I<httpd>, I<ssl>, I<enable>, I<disable>,
I<pemfile>, I<allow>, I<read-only>, I<check>, I<init>, I<count>,
I<pidfile>, I<statefile>, I<group>, I<start>, I<stop>, I<uid>,
I<gid>, I<connection>, I<port(number)>, I<unix(socket)>, I<type>,
I<proto(col)>, I<tcp>, I<tcpssl>, I<udp>, I<alert>, I<icmp>,
I<mail-format>, I<restart>, I<timeout>, I<checksum>, I<resource>,
I<expect>, I<send>, I<mailserver>, I<every>, I<mode>, I<active>,
I<passive>, I<manual>, I<depends>, I<host>, I<default>, I<http>,
-I<ftp>, I<smtp>, I<pop>, I<ntp3>, I<nntp>, I<imap>, I<ssh>,
+I<ftp>, I<smtp>, I<pop>, I<ntp3>, I<nntp>, I<imap>, I<clamav>, I<ssh>,
I<dwp>, I<ldap2>, I<ldap3>, I<tns>, I<request>, I<cpu>, I<mem>,
I<totalmem>, I<children>, I<loadavg>, I<timestamp>, I<changed>,
I<second(s)>, I<minute(s)>, I<hour(s)>, I<day(s)>, I<space>,
I<inode>, I<pid>, I<ppid>, I<perm(ission)>, I<process>, I<file>,
I<directory>, I<device>, I<size>, I<unmonitor>, I<rdate>,
I<rsync>, I<data>, I<invalid>, I<exec>, I<nonexist>, I<policy>,
I<reminder>, I<instance>, I<eventqueue>, I<basedir>, I<slot(s)>,
I<system> and I<failed>
Index: p.y
===================================================================
RCS file: /sources/monit/monit/p.y,v
retrieving revision 1.239
diff -u -8 -p -r1.239 p.y
--- p.y 19 Jul 2006 17:33:37 -0000 1.239
+++ p.y 25 Aug 2006 15:43:51 -0000
@@ -247,17 +247,17 @@
%token SET LOGFILE FACILITY DAEMON SYSLOG MAILSERVER HTTPD ALLOW ADDRESS INIT
%token READONLY CLEARTEXT MD5HASH SHA1HASH CRYPT
%token PEMFILE ENABLE DISABLE HTTPDSSL CLIENTPEMFILE ALLOWSELFCERTIFICATION
%token STATEFILE SEND EXPECT CYCLE COUNT REMINDER
%token PIDFILE START STOP PATHTOK
%token HOST PORT TYPE UDP TCP TCPSSL PROTOCOL CONNECTION
%token ALERT MAILFORMAT UNIXSOCKET SIGNATURE
%token TIMEOUT RESTART CHECKSUM EVERY
-%token DEFAULT HTTP APACHESTATUS FTP SMTP POP IMAP NNTP NTP3 MYSQL DNS
+%token DEFAULT HTTP APACHESTATUS FTP SMTP POP IMAP CLAMAV NNTP NTP3 MYSQL DNS
%token SSH DWP LDAP2 LDAP3 RDATE RSYNC TNS PGSQL POSTFIXPOLICY
%token <string> STRING PATH MAILADDR MAILFROM MAILSUBJECT
%token <string> MAILBODY SERVICENAME STRINGNAME
%token <number> NUMBER PERCENT LOGLIMIT CLOSELIMIT DNSLIMIT KEEPALIVELIMIT
%token <number> REPLYLIMIT REQUESTLIMIT STARTLIMIT WAITLIMIT GRACEFULLIMIT
%token <number> CLEANUPLIMIT
%token <real> REAL
%token CHECKPROC CHECKDEV CHECKFILE CHECKDIR CHECKHOST CHECKSYSTEM CHECKFIFO
@@ -873,16 +873,19 @@ protocol : /* EMPTY */ {
portset.protocol= addprotocol(P_FTP);
}
| PROTOCOL HTTP request {
portset.protocol= addprotocol(P_HTTP);
}
| PROTOCOL IMAP {
portset.protocol= addprotocol(P_IMAP);
}
+ | PROTOCOL CLAMAV {
+ portset.protocol= addprotocol(P_CLAMAV);
+ }
| PROTOCOL LDAP2 {
portset.protocol= addprotocol(P_LDAP2);
}
| PROTOCOL LDAP3 {
portset.protocol= addprotocol(P_LDAP3);
}
| PROTOCOL MYSQL {
portset.protocol= addprotocol(P_MYSQL);
@@ -2408,17 +2411,18 @@ static void *addprotocol(int protocol) {
switch (protocol) {
case P_APACHESTATUS: return create_apache_status();
case P_DNS: return create_dns();
case P_DWP: return create_dwp();
case P_FTP: return create_ftp();
case P_GENERIC: return create_generic();
case P_HTTP: return create_http();
- case P_IMAP: return create_imap();
+ case IMAP: return create_imap();
+ case P_CLAMAV: return create_clamav();
case P_LDAP2: return create_ldap2();
case P_LDAP3: return create_ldap3();
case P_MYSQL: return create_mysql();
case P_NNTP: return create_nntp();
case P_NTP3: return create_ntp3();
case P_POSTFIXPOLICY: return create_postfix_policy();
case P_POP: return create_pop();
case P_SMTP: return create_smtp();
Index: protocols/clamav.c
===================================================================
RCS file: protocols/clamav.c
diff -N protocols/clamav.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ protocols/clamav.c 25 Aug 2006 15:43:51 -0000
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C), 2000-2006 by the monit project group.
+ * All Rights Reserved.
+ *
+ * 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
+ */
+
+#include <config.h>
+
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#include "protocol.h"
+
+/**
+ * Send PING and check for PONG.
+ * If alive return TRUE, else, return FALSE.
+ *
+ * @author
+ *
+ * @version $
+ *
+ * @file
+ */
+int check_clamav(Socket_T s) {
+
+ char buf[STRLEN];
+ const char *ok= "PONG";
+
+ ASSERT(s);
+
+ if(socket_print(s, "PING\r\n") < 0) {
+ LogError("CLAMAV: error sending data -- %s\n", STRERROR);
+ return FALSE;
+ }
+
+ if(!socket_readln(s, buf, sizeof(buf))) {
+ LogError("CLAMAV: error receiving data -- %s\n", STRERROR);
+ return FALSE;
+ }
+
+ Util_chomp(buf);
+
+ if(strncasecmp(buf, ok, strlen(ok)) != 0) {
+ LogError("CLAMAV error: %s\n", buf);
+ return FALSE;
+ }
+
+ return TRUE;
+
+}
+
Index: protocols/protocol.c
===================================================================
RCS file: /sources/monit/monit/protocols/protocol.c,v
retrieving revision 1.27
diff -u -8 -p -r1.27 protocol.c
--- protocols/protocol.c 22 Jan 2006 19:47:36 -0000 1.27
+++ protocols/protocol.c 25 Aug 2006 15:43:52 -0000
@@ -37,16 +37,17 @@
static Protocol_T myapache_status= NULL;
static Protocol_T mydefault= NULL;
static Protocol_T mydns= NULL;
static Protocol_T mydwp= NULL;
static Protocol_T myftp= NULL;
static Protocol_T mygeneric= NULL;
static Protocol_T myhttp= NULL;
static Protocol_T myimap= NULL;
+static Protocol_T myclamav= NULL;
static Protocol_T myldap2= NULL;
static Protocol_T myldap3= NULL;
static Protocol_T mymysql= NULL;
static Protocol_T mynntp= NULL;
static Protocol_T myntp3= NULL;
static Protocol_T mypostfix_policy= NULL;
static Protocol_T mypop= NULL;
static Protocol_T mysmtp= NULL;
@@ -77,16 +78,17 @@ void gc_protocols() {
FREE(myapache_status);
FREE(mydefault);
FREE(mydns);
FREE(mydwp);
FREE(myftp);
FREE(mygeneric);
FREE(myhttp);
FREE(myimap);
+ FREE(myclamav);
FREE(myldap2);
FREE(myldap3);
FREE(mymysql);
FREE(mynntp);
FREE(myntp3);
FREE(mypostfix_policy);
FREE(mypop);
FREE(mysmtp);
@@ -173,16 +175,24 @@ void *create_imap() {
if(myimap == NULL) {
NEW(myimap);
myimap->name= "IMAP";
myimap->check= check_imap;
}
return myimap;
}
+void *create_clamav() {
+ if(myclamav == NULL) {
+ NEW(myclamav);
+ myclamav->name= "CLAMAV";
+ myclamav->check= check_clamav;
+ }
+ return myclamav;
+}
void *create_ldap2() {
if(myldap2 == NULL) {
NEW(myldap2);
myldap2->name= "LDAP2";
myldap2->check= check_ldap2;
}
return myldap2;
Index: protocols/protocol.h
===================================================================
RCS file: /sources/monit/monit/protocols/protocol.h,v
retrieving revision 1.25
diff -u -8 -p -r1.25 protocol.h
--- protocols/protocol.h 22 Jan 2006 19:47:36 -0000 1.25
+++ protocols/protocol.h 25 Aug 2006 15:43:52 -0000
@@ -43,28 +43,30 @@
#define P_GENERIC 14
#define P_APACHESTATUS 15
#define P_NTP3 16
#define P_MYSQL 17
#define P_DNS 18
#define P_POSTFIXPOLICY 19
#define P_TNS 20
#define P_PGSQL 21
+#define P_CLAMAV 22
void gc_protocols();
/* Protocol Factory routines */
void* create_apache_status();
void* create_default();
void* create_dns();
void* create_dwp();
void* create_ftp();
void* create_generic();
void* create_http();
void* create_imap();
+void* create_clamav();
void* create_ldap2();
void* create_ldap3();
void* create_mysql();
void* create_nntp();
void* create_ntp3();
void* create_postfix_policy();
void* create_pop();
void* create_smtp();
@@ -78,16 +80,17 @@ void* create_pgsql();
int check_apache_status(Socket_T);
int check_default(Socket_T);
int check_dns(Socket_T);
int check_dwp(Socket_T);
int check_ftp(Socket_T);
int check_generic(Socket_T);
int check_http(Socket_T);
int check_imap(Socket_T);
+int check_clamav(Socket_T);
int check_ldap2(Socket_T);
int check_ldap3(Socket_T);
int check_mysql(Socket_T);
int check_nntp(Socket_T);
int check_ntp3(Socket_T);
int check_postfix_policy(Socket_T);
int check_pop(Socket_T);
int check_smtp(Socket_T);
_______________________________________________
monit-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/monit-dev