[Pkg-nagios-changes] [SCM] Debian packaging for nagircbot branch, master, updated. f0aea80aa670697af6e60ce7600689f189279898
John Morrissey
jwm at horde.net
Wed May 25 18:00:16 UTC 2011
The following commit has been merged in the master branch:
commit 56876c66c6af2958dea7f7ef2220c3e7c1a75f6d
Author: John Morrissey <jwm at horde.net>
Date: Wed May 25 13:13:51 2011 -0400
Imported Upstream version 0.0.33
diff --git a/Makefile b/Makefile
index c001426..7ff56f5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
-# (C) 2006-2010 by folkert at vanheusden.com GPLv2 applies
+# (C) 2006-2011 by folkert at vanheusden.com GPLv2 applies
-VERSION=0.0.32
+VERSION=0.0.33
DEBUG= -g -D_DEBUG #-fprofile-arcs -ftest-coverage # -pg -g
CXXFLAGS+=-Wall -O2 -DVERSION=\"${VERSION}\" $(DEBUG)
diff --git a/anna.cpp b/anna.cpp
index 8564c09..a05e1e4 100644
--- a/anna.cpp
+++ b/anna.cpp
@@ -1,4 +1,4 @@
-/* (C) 2006-2010 by folkert at vanheusden.com GPLv2 applies */
+/* (C) 2006-2011 by folkert at vanheusden.com GPLv2 applies */
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
@@ -60,7 +60,7 @@ char use_colors = 0;
char topic_summary = 0;
char hard_only = 1;
int max_time_last_host_update = 300, max_time_oldest_host_update = 3600, max_time_last_host_check = 300, max_time_oldest_host_check = 3 * 86400, max_time_last_service_check = 20 * 60, max_time_oldest_service_check = 3 * 86400, max_time_oldest_next_service_check = 20 * 60;
-int irc_server_keep_alive = 300; /* send an irc-command at least every 300 seconds (currently 'TIME') */
+int irc_server_keep_alive = 60; /* send an irc-command at least every 300 seconds (currently 'TIME') */
int announce_global_status_interval = 0;
time_t last_announce_global_status_interval = 0;
char critical_only = 0;
@@ -89,11 +89,9 @@ int send_irc(server_t server_conn, char *format, ...)
vsnprintf(buffer, sizeof(buffer) - 3, format, ap);
va_end(ap);
- strcat(buffer, "\r\n"); /* yes this is safe: check the vsnprintf command */
+ if (verbose > 1) dolog("OUT: `%s'", buffer);
-#ifdef _DEBUG
- printf("%s", buffer);
-#endif
+ strcat(buffer, "\r\n"); /* yes this is safe: check the vsnprintf command */
rc = IRCWRITE(server_conn, buffer, strlen(buffer));
if (rc == -1)
@@ -594,171 +592,184 @@ int do_nagircbot(server_t server_conn, char *channel)
}
else
{
- char *cmd;
- char *crlf;
+ char *next_response = recv_buffer;
+ char *response = NULL;
+ char *cmd = NULL;
+ char *crlf = NULL;
recv_buffer[rc] = 0x00;
- if (verbose > 1) dolog("IN: %s", recv_buffer);
+ while ((response = next_response)
+ && (crlf = strchr( response, '\r')))
+ {
+ if (*(crlf + 1) != '\n')
+ {
+ dolog( "Malformed server response: `%s' at `%s'.", recv_buffer, response );
+ return -1;
+ }
- crlf = strchr(recv_buffer, '\r');
- if (crlf) *crlf = 0x00;
- if (!crlf) crlf = strchr(recv_buffer, '\n');
- if (crlf) *crlf = 0x00;
+ *crlf = '\0';
+ if (( crlf + 2 ) - recv_buffer < rc)
+ next_response = crlf + 2;
+ else
+ next_response = NULL;
- if (check_ping(server_conn, recv_buffer) == -1)
- return -1;
+ if (verbose > 1) dolog("IN: `%s'", response);
- cmd = strchr(recv_buffer, ' ');
- if (cmd)
- {
- while(*cmd == ' ') cmd++;
+ if (check_ping(server_conn, response) == -1)
+ return -1;
- if (strncmp(cmd, "KICK ", 5) == 0)
+ cmd = strchr(response, ' ');
+ if (cmd)
{
- char *dummy = strchr(cmd, ' ');
- if (dummy)
- {
- while(*dummy == ' ') dummy++;
- dummy = strchr(dummy, ' ');
- }
- if (dummy)
- {
- while(*dummy == ' ') dummy++;
+ while(*cmd == ' ') cmd++;
- if (strncmp(dummy, nick, strlen(nick)) == 0)
+ if (strncmp(cmd, "KICK ", 5) == 0)
+ {
+ char *dummy = strchr(cmd, ' ');
+ if (dummy)
{
- dolog("nagircbot got kicked (%s)", recv_buffer);
- return -1;
+ while(*dummy == ' ') dummy++;
+ dummy = strchr(dummy, ' ');
}
- else if (verbose > 1)
+ if (dummy)
{
- dolog("user %s got kicked from channel", dummy);
+ while(*dummy == ' ') dummy++;
+
+ if (strncmp(dummy, nick, strlen(nick)) == 0)
+ {
+ dolog("nagircbot got kicked (%s)", response);
+ return -1;
+ }
+ else if (verbose > 1)
+ {
+ dolog("user %s got kicked from channel", dummy);
+ }
}
}
- }
- else if (strncmp(cmd, "PRIVMSG ", 8) == 0)
- {
- /* :flok!~flok at rammstein.amc.nl PRIVMSG nagircbot :test */
-
- char *to_me = &cmd[8];
- while(*to_me == ' ') to_me++;
-
- /* message to this bot? */
- if (strncmp(to_me, nick, strlen(nick)) == 0)
+ else if (strncmp(cmd, "PRIVMSG ", 8) == 0)
{
- /* yes */
- char *msg = strchr(cmd, ':');
- char *from_who = recv_buffer + 1;
- char *dummy = strchr(from_who, '!');
+ /* :flok!~flok at rammstein.amc.nl PRIVMSG nagircbot :test */
- if (msg != NULL && dummy != NULL)
+ char *to_me = &cmd[8];
+ while(*to_me == ' ') to_me++;
+
+ /* message to this bot? */
+ if (strncmp(to_me, nick, strlen(nick)) == 0)
{
- msg++;
- *dummy = 0x00;
+ /* yes */
+ char *msg = strchr(cmd, ':');
+ char *from_who = response + 1;
+ char *dummy = strchr(from_who, '!');
- if (strcasecmp(msg, "help") == 0)
+ if (msg != NULL && dummy != NULL)
{
- int rc = 0;
-
- dolog("help requested by %s", from_who);
+ msg++;
+ *dummy = 0x00;
- rc |= irc_privmsg(server_conn, from_who, "resend - resend the last known problems");
- rc |= irc_privmsg(server_conn, from_who, "statistics - returns the number of criticals/warnings/etc.");
- rc |= irc_privmsg(server_conn, from_who, "reload - completely forced reload the nagios status");
- rc |= irc_privmsg(server_conn, from_who, "check - check if nagios is still running");
+ if (strcasecmp(msg, "help") == 0)
+ {
+ int rc = 0;
- if (rc == -1)
- return -1;
- }
- else if (strcmp(msg, "resend") == 0)
- {
- dolog("resend requested by %s", from_who);
+ dolog("help requested by %s", from_who);
- if (resend_nagios_status(server_conn, from_who) == -1)
- return -1;
- }
- else if (strcmp(msg, "check") == 0)
- {
- char *message;
- int rc;
+ rc |= irc_privmsg(server_conn, from_who, "resend - resend the last known problems");
+ rc |= irc_privmsg(server_conn, from_who, "statistics - returns the number of criticals/warnings/etc.");
+ rc |= irc_privmsg(server_conn, from_who, "reload - completely forced reload the nagios status");
+ rc |= irc_privmsg(server_conn, from_who, "check - check if nagios is still running");
- dolog("nagios check requested by %s", from_who);
+ if (rc == -1)
+ return -1;
+ }
+ else if (strcmp(msg, "resend") == 0)
+ {
+ dolog("resend requested by %s", from_who);
- message = check_nagios();
- if (message)
+ if (resend_nagios_status(server_conn, from_who) == -1)
+ return -1;
+ }
+ else if (strcmp(msg, "check") == 0)
{
- char buffer[4096];
- snprintf(buffer, sizeof(buffer), "Nagios has stopped running! -> %s", message);
- rc = irc_privmsg(server_conn, from_who, buffer);
- free(message);
+ char *message;
+ int rc;
+
+ dolog("nagios check requested by %s", from_who);
+
+ message = check_nagios();
+ if (message)
+ {
+ char buffer[4096];
+ snprintf(buffer, sizeof(buffer), "Nagios has stopped running! -> %s", message);
+ rc = irc_privmsg(server_conn, from_who, buffer);
+ free(message);
+ }
+ else
+ rc = irc_privmsg(server_conn, from_who, "Nagios is still running");
+
+ if (rc == -1)
+ return -1;
}
- else
- rc = irc_privmsg(server_conn, from_who, "Nagios is still running");
-
- if (rc == -1)
- return -1;
- }
- else if (strcmp(msg, "statistics") == 0)
- {
- char buffer[4096];
+ else if (strcmp(msg, "statistics") == 0)
+ {
+ char buffer[4096];
- dolog("statistics requested by %s", from_who);
+ dolog("statistics requested by %s", from_who);
- calc_statistics(prev, n_prev, 0, 0, 0, 1, buffer, sizeof(buffer));
+ calc_statistics(prev, n_prev, 0, 0, 0, 1, buffer, sizeof(buffer));
- if (irc_privmsg(server_conn, from_who, buffer) == -1)
- return -1;
- }
- else if (strcmp(msg, "reload") == 0)
- {
- dolog("reload requested by %s", from_who);
-
- if (reload_statuslog() == -1)
- {
- if (irc_privmsg(server_conn, from_who, "cannot access status.log") == -1)
+ if (irc_privmsg(server_conn, from_who, buffer) == -1)
return -1;
}
- else
+ else if (strcmp(msg, "reload") == 0)
{
- if (irc_privmsg(server_conn, from_who, "nagios status reloaded") == -1)
- return -1;
+ dolog("reload requested by %s", from_who);
+
+ if (reload_statuslog() == -1)
+ {
+ if (irc_privmsg(server_conn, from_who, "cannot access status.log") == -1)
+ return -1;
+ }
+ else
+ {
+ if (irc_privmsg(server_conn, from_who, "nagios status reloaded") == -1)
+ return -1;
+ }
}
- }
- else
- {
- char buffer[4096];
+ else
+ {
+ char buffer[4096];
- dolog("giberish sent by %s", from_who);
+ dolog("giberish sent by %s", from_who);
- snprintf(buffer, sizeof(buffer), "'%s' is not understood - send 'help' for help", msg);
- if (irc_privmsg(server_conn, from_who, buffer) == -1)
- return -1;
+ snprintf(buffer, sizeof(buffer), "'%s' is not understood - send 'help' for help", msg);
+ if (irc_privmsg(server_conn, from_who, buffer) == -1)
+ return -1;
- if (send_help(server_conn, from_who) == -1)
- return -1;
+ if (send_help(server_conn, from_who) == -1)
+ return -1;
+ }
}
}
- }
- }
- else if (strncmp(cmd, "QUIT ", 5) == 0)
- {
- char *quit_nick = &recv_buffer[1];
- char *exclamation_mark = strchr(quit_nick, '!');
- if (exclamation_mark) *exclamation_mark = 0x00;
-
- if (strcmp(nick, quit_nick) == 0)
- {
- dolog("Got QUITed (%s)", cmd);
- return -1;
}
- else if (verbose > 1)
+ else if (strncmp(cmd, "QUIT ", 5) == 0)
{
- dolog("user %s quit", quit_nick);
+ char *quit_nick = &response[1];
+ char *exclamation_mark = strchr(quit_nick, '!');
+ if (exclamation_mark) *exclamation_mark = 0x00;
+
+ if (strcmp(nick, quit_nick) == 0)
+ {
+ dolog("Got QUITed (%s)", cmd);
+ return -1;
+ }
+ else if (verbose > 1)
+ {
+ dolog("user %s quit", quit_nick);
+ }
}
- }
+ }
}
}
}
@@ -782,7 +793,7 @@ void sighandler(int pid)
void version(void)
{
- printf("nagircbot, v" VERSION " (C) 2006-2008 by folkert at vanheusden.com\n");
+ printf("nagircbot, v" VERSION " (C) 2006-2011 by folkert at vanheusden.com\n");
}
void usage(void)
--
Debian packaging for nagircbot
More information about the Pkg-nagios-changes
mailing list