monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[monit-dev] [monit] r220 committed - added memcache protocol test (thank


From: monit
Subject: [monit-dev] [monit] r220 committed - added memcache protocol test (thanks to Sebastien Debrard for patch)
Date: Wed, 18 Aug 2010 14:14:09 +0000

Revision: 220
Author: martin2812
Date: Wed Aug 18 07:12:59 2010
Log: added memcache protocol test (thanks to Sebastien Debrard for patch)
http://code.google.com/p/monit/source/detail?r=220

Added:
 /trunk/protocols/memcache.c
Modified:
 /trunk/CHANGES.txt
 /trunk/l.l
 /trunk/monit.pod
 /trunk/p.y
 /trunk/protocols/protocol.c
 /trunk/protocols/protocol.h

=======================================
--- /dev/null
+++ /trunk/protocols/memcache.c Wed Aug 18 07:12:59 2010
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2010 Tildeslash Ltd. 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 version 3.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ *
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+
+#include <config.h>
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "protocol.h"
+
+#define MEMCACHELEN 24
+
+/* Magic Byte */
+#define MAGIC_REQUEST      0x80
+#define MAGIC_RESPONSE     0x81
+
+/* Response Status */
+#define NO_ERROR           0x0000
+#define KEY_NOT_FOUND      0x0001
+#define KEY_EXISTS         0x0002
+#define VALUE_TOO_BIG      0x0003
+#define INVALID_ARGUMENTS  0x0004
+#define ITEM_NOT_STORED    0x0005
+#define UNKNOWN_COMMAND    0x0081
+#define OUT_OF_MEMORY      0x0082
+
+/**
+ *  Memcache binary protocol
+ *
+ *  Send No-op request
+ *
+ *  @author Sébastien Debrard <address@hidden>
+ *
+ *  @file
+ */
+int check_memcache(Socket_T s) {
+  unsigned int length;
+  unsigned char response[STRLEN];
+  unsigned int status;
+
+  unsigned char request[MEMCACHELEN] = {
+    MAGIC_REQUEST,                    /** Magic */
+    0x0a,                             /** Opcode */
+    0x00, 0x00,                       /** Key length */
+    0x00,                             /** Extra length */
+    0x00,                             /** Data type */
+ 0x00, 0x00, /** request Reserved / response Status */
+    0x00, 0x00, 0x00, 0x00,           /** Total body */
+    0x00, 0x00, 0x00, 0x00,           /** Opaque */
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00    /** CAS */
+  };
+
+  ASSERT(s);
+
+  if(socket_write(s, (unsigned char *)request, sizeof(request)) <= 0) {
+    LogError("MEMCACHE: error sending data -- %s\n", STRERROR);
+    return FALSE;
+  }
+
+  /* Response should have at least MEMCACHELEN bytes */
+  length = socket_read(s, (unsigned char *)response, sizeof(response));
+  if (length != MEMCACHELEN) {
+ LogError("MEMCACHE: Received %d bytes from server, expected %d bytes\n", length, MEMCACHELEN);
+    return FALSE;
+  }
+
+  if(response[0] != MAGIC_RESPONSE) {
+    LogError("MEMCACHELEN: Invalid response code -- error occured\n");
+    return FALSE;
+  }
+
+  status = (response[6] << 8) | response[7];
+  switch( status ) {
+    case NO_ERROR:
+      return TRUE;
+    case OUT_OF_MEMORY:
+      LogError("MEMCACHELEN: Invalid response code -- Out of memory\n");
+      return FALSE;
+    case UNKNOWN_COMMAND:
+      LogError("MEMCACHELEN: Invalid response code -- Unknown command\n");
+      return FALSE;
+    case INVALID_ARGUMENTS:
+ LogError("MEMCACHELEN: Invalid response code -- Invalid arguments\n");
+      return FALSE;
+    case VALUE_TOO_BIG:
+      LogError("MEMCACHELEN: Invalid response code -- Value too big\n");
+      return FALSE;
+    case ITEM_NOT_STORED:
+      LogError("MEMCACHELEN: Invalid response code -- Item not stored\n");
+      return FALSE;
+    case KEY_NOT_FOUND:
+      LogError("MEMCACHELEN: Invalid response code -- Key not found\n");
+      return FALSE;
+    case KEY_EXISTS:
+      LogError("MEMCACHELEN: Invalid response code -- Key exists\n");
+      return FALSE;
+    default:
+ LogError("MEMCACHELEN: Unknow response code %u -- error occured\n", status);
+      return FALSE;
+  }
+
+  return FALSE;
+
+}
+
+
=======================================
--- /trunk/CHANGES.txt  Mon Jul 26 12:10:25 2010
+++ /trunk/CHANGES.txt  Wed Aug 18 07:12:59 2010
@@ -41,15 +41,16 @@
CPU usage on MacOSX still requires monit to run as root, otherwise it will display
   process' cpu usage as 0.

-* Remove configuration limit of 20 ICMP requests per cycle.
+* Remove the configuration limit of 20 ICMP requests per cycle.

 * Monit now registers credentials with M/Monit automatically, so it's not
necessary to set it manually in M/Monit anymore in order to manage services
   on Monit host. The automatic credentials registration can be disabled:
set mmonit http://monit:address@hidden:8080/collector and register without credentials

-* Added FIPS OpenSSL module to Monit httpd. Many thanks to Lior Okman
-  for providing the patch.
+* Added MEMCACHE protocol test. Thanks to Sébastien Debrard for the patch.
+
+* Added FIPS OpenSSL module to Monit httpd. Thanks to Lior Okman for the patch.

 BUGFIXES:

=======================================
--- /trunk/l.l  Sat Jul 24 04:27:48 2010
+++ /trunk/l.l  Wed Aug 18 07:12:59 2010
@@ -223,6 +223,7 @@
 sip               { return SIP; }
 gps               { return GPS; }
 radius            { return RADIUS; }
+memcache          { return MEMCACHE; }
 target            { return TARGET; }
 maxforward        { return MAXFORWARD; }
 mode              { return MODE; }
=======================================
--- /trunk/monit.pod    Fri Jul 30 14:15:04 2010
+++ /trunk/monit.pod    Wed Aug 18 07:12:59 2010
@@ -1961,6 +1961,7 @@
  I<LDAP2>
  I<LDAP3>
  I<LMTP>
+ I<MEMCACHE>
  I<MYSQL>
  I<NNTP>
  I<NTP3>
=======================================
--- /trunk/p.y  Mon Jul 26 09:21:41 2010
+++ /trunk/p.y  Wed Aug 18 07:12:59 2010
@@ -279,7 +279,7 @@
 %token ALERT NOALERT MAILFORMAT UNIXSOCKET SIGNATURE
 %token TIMEOUT RESTART CHECKSUM EVERY
%token DEFAULT HTTP APACHESTATUS FTP SMTP POP IMAP CLAMAV NNTP NTP3 MYSQL DNS -%token SSH DWP LDAP2 LDAP3 RDATE RSYNC TNS PGSQL POSTFIXPOLICY SIP LMTP GPS RADIUS +%token SSH DWP LDAP2 LDAP3 RDATE RSYNC TNS PGSQL POSTFIXPOLICY SIP LMTP GPS RADIUS MEMCACHE
 %token <string> STRING PATH MAILADDR MAILFROM MAILSUBJECT
 %token <string> MAILBODY SERVICENAME STRINGNAME
 %token <number> NUMBER PERCENT LOGLIMIT CLOSELIMIT DNSLIMIT KEEPALIVELIMIT
@@ -1063,6 +1063,9 @@
                 | PROTOCOL RADIUS secret {
                     portset.protocol = addprotocol(P_RADIUS);
                   }
+                | PROTOCOL MEMCACHE {
+                    portset.protocol = addprotocol(P_MEMCACHE);
+                  }
                 | sendexpectlist {
                     portset.protocol = addprotocol(P_GENERIC);
                   }
@@ -2648,6 +2651,7 @@
   case P_LMTP:          return create_lmtp();
   case P_GPS:           return create_gps();
   case P_RADIUS:        return create_radius();
+  case P_MEMCACHE:      return create_memcache();
   }

   return create_default();
=======================================
--- /trunk/protocols/protocol.c Fri Jan  8 03:20:43 2010
+++ /trunk/protocols/protocol.c Wed Aug 18 07:12:59 2010
@@ -70,6 +70,7 @@
 static Protocol_T mysip= NULL;
 static Protocol_T mygps= NULL;
 static Protocol_T myradius= NULL;
+static Protocol_T mymemcache= NULL;


 /**
@@ -113,6 +114,7 @@
   FREE(mysip);
   FREE(mygps);
   FREE(myradius);
+  FREE(mymemcache);

 }

@@ -372,3 +374,12 @@
   return myradius;
 }

+void *create_memcache() {
+  if(mymemcache == NULL) {
+    NEW(mymemcache);
+    mymemcache->name= "MEMCACHE";
+    mymemcache->check= check_memcache;
+  }
+  return mymemcache;
+}
+
=======================================
--- /trunk/protocols/protocol.h Fri Jan  8 03:20:43 2010
+++ /trunk/protocols/protocol.h Wed Aug 18 07:12:59 2010
@@ -63,6 +63,7 @@
 #define P_LMTP           24
 #define P_GPS            25
 #define P_RADIUS         26
+#define P_MEMCACHE       27

 void  gc_protocols();

@@ -93,6 +94,7 @@
 void* create_lmtp();
 void* create_gps();
 void* create_radius();
+void* create_memcache();

 /* "Package" locale Protocol routines */
 int check_apache_status(Socket_T);
@@ -121,6 +123,7 @@
 int check_lmtp(Socket_T);
 int check_gps(Socket_T);
 int check_radius(Socket_T);
+int check_memcache(Socket_T);


 #endif

reply via email to

[Prev in Thread] Current Thread [Next in Thread]