./nagzilla/CHANGELOG0000755000175000017500000000231211207561560014406 0ustar billfordbillford05/28/2009
-- Removed external loading of config file options
05/27/2009
-- Added some rudimentary IP address access control
05/26/2009
-- finished up multiple client support (Thanks for the troubleshooting Lebbeous and Steve!)
-- added a utilities directory with a couple stress testing bash scripts (see TODO)
05/18/2009
-- Added patches from
01/10/2009
-- Removed specfics from and commented config file
-- User to run as is now hard coded (nobody) -- will change later
-- Added a sample log rotate script to archive
01/09/2009
-- Added user change
-- Added liblog-loglite-perl module to help with logging
-- Added very simple logging
12/13/2008 -- Replaced old guy code with some young guy code (array handling and such)
-- Added the ability for Nagzilla to accept subscription requests for roster addition --
-- Above feature currently requires a restart -- hopefully next release will be cooler
10/24/2008 -- Applied Patch from hakamadare via Google Code
-- fixed config file issues
-- added require directive to a couple modules
-- added SSL / TLS / SASL
-- added debug option for connection to Jabber server
-- applied by BM
./nagzilla/LICENSE0000755000175000017500000003503611207134665014214 0ustar billfordbillford
The GNU General Public License (GPL)
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
./nagzilla/nagzillac.cfg0000755000175000017500000000020411207134665015621 0ustar billfordbillford#nagzillac configuration file
#Nagzilla server to connect to
NagzillaServer =
#Nagzilla Server port to use
NagzillaPort = 49776
./nagzilla/nagzillac.pl0000755000175000017500000000166211207561775015514 0ustar billfordbillford#!/usr/bin/perl
#(c)2007-2009 Hurricane Labs
#Author: Billford
#License: See LICENSE file GPL v2
#Nagzilla Jabber Relay Client
require Config::Simple;
require Data::Dumper;
use IO::Socket;
use IO::Socket::INET;
#bring in our configuration variables
$CONFDIR = "/etc/nagzillac";
# DO NOT EDIT ANYTHING BEYOND THIS POINT!!
##################Begin Config Setup########################
Config::Simple->import_from('nagzillac.cfg', \%Config);
$cfg = new Config::Simple("$CONFDIR/nagzillac.cfg");
#Nagzillac Nagzilla Server Settings
$nagzillaserver = $cfg->param("NagzillaServer");
$nagzillaport = $cfg->param("NagzillaPort");
##################End Config Setup##########################
#Let's make us a socket connection
$remote = IO::Socket::INET->new(
Proto => 'tcp',
PeerAddr => "$nagzillaserver",
PeerPort => "$nagzillaport",
Reuse => 1
) or die "$!";
$remote->autoflush(1);
print $remote $ARGV[0];
close $remote;
./nagzilla/nagzillad0000755000175000017500000000043511207134665015072 0ustar billfordbillford/var/log/nagzillad.log {
daily
missingok
rotate 356
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
/etc/init.d/nagzillad restart > /dev/null
endscript
}
./nagzilla/nagzillad.cfg0000755000175000017500000000222511207314717015625 0ustar billfordbillford####Configuration File for Nagzillad ###
###(c)2008 Hurricane Labs, LLC #########
#Nagzillad Server Settings
#IP to bind to
BindAddr =
#Port to bind to
BindPort = 49776
#Username to run as
BindUser = nobody
#Run as daemon, use 1 - to run in foreground use 0
Daemon = 1
#To log server starts and stop and messages sent use 1
To_Log = 1
#Where would you like to log to today?
Log_Directory = /var/log
#Default error log level
Error_Log_Level = 6
#Nagzillad Access Control
AllowedIPAddr = {comma separated list of IP addresses allowed to connect}
#Jabber Server Settings
#Jabber Server to connect to
JabberServer = naggydev
#Jabber Port
JabberPort = 5222
#Debug Messages on or off
JabberDebug = 0
#Jabber User
JabberUser =
#Jabber Password
JabberPass =
#Jabber Resource to use
JabberResource =
#Time to wait between sending message
JabberMaxWait = 2
#To use TLS or not
JabberTLS = 1
#To use SSL or not
JabberSSL = 0
#To use SASL or not
JabberSASL = 1
#Conference Server Settings
#Jabber Conference Server
ConfServer = conference.naggydev
#comma separated list of conference room names
ConfRooms =
#Nick to use in the conference rooms
ConfNick = nagzilla
./nagzilla/nagzillad.pl0000755000175000017500000001476611207561751015520 0ustar billfordbillford#!/usr/bin/perl
#(c)2007-2009 Hurricane Labs
#Author: Billford
#License: See LICENSE file GPL v2
#Nagzilla Jabber Relay Bot Server
#import our required Perl modules
require Config::Simple;
require Data::Dumper;
require Log::LogLite;
use IO::Socket;
use IO::Socket::INET;
use IO::Select;
use Net::Jabber qw(Client);
use Net::Jabber qw(Message);
use Net::Jabber qw(Protocol);
use Net::Jabber qw(Presence);
$CONFDIR = "/etc/nagzillad";
# DO NOT EDIT ANYTHING BEYOND THIS POINT!!
##############Config File Setup#####################
Config::Simple->import_from('nagzillad.cfg', \%Config);
$cfg = new Config::Simple("$CONFDIR/nagzillad.cfg");
#Nagzillad Server Settings
$bindaddr = $cfg->param("BindAddr");
$bindport = $cfg->param("BindPort");
$binduser = $cfg->param("BindUser");
$daemon = $cfg->param("Daemon");
$to_log = $cfg->param("To_Log");
$LOG_DIRECTORY = $cfg->param("Log_Directory");
$ERROR_LOG_LEVEL = $cfg->param("Error_Log_Level");
#Nagzillad Access Control
@allowedipaddr = $cfg->param("AllowedIPAddr");
#Jabber Server Settings
$jabberserver = $cfg->param("JabberServer");
$jabberport = $cfg->param("JabberPort");
$jabberdebug = $cfg->param("JabberDebug");
$jabbertls = $cfg->param("JabberTLS");
$jabberssl = $cfg->param("JabberSSL");
$jabbersasl = $cfg->param("JabberSASL");
$jabberuser = $cfg->param("JabberUser");
$jabberpass = $cfg->param("JabberPass");
$jabberresource = $cfg->param("JabberResource");
$jabbermaxwait = $cfg->param("JabberMaxWait");
#conference server settings
$confserver = $cfg->param("ConfServer");
@confrooms = $cfg->param("ConfRooms");
$confnick = $cfg->param("ConfNick");
@roominess = @confrooms;
###########End Config Setup#####################
my $log = new Log::LogLite( $LOG_DIRECTORY . "/nagzillad.log", $ERROR_LOG_LEVEL );
# make_access_checker - returns a function which checks if an IP address
# should be allowed to connect to this nagzillad.
#
# It takes a reference to an an array of IP addresses (dotted quad strings).
#
# It returns a function which takes an IP address (also a dotted quad
# string). That function will return 1 if the IP address is allowed and
# undef if it isn't.
#
sub make_access_checker {
my $ok_addrs = shift;
my %ok_addr_set = map { $_ => 1 } @{$ok_addrs};
return sub {
my $addr = shift;
return $ok_addr_set{$addr};
}
}
my $check_access = make_access_checker(\@allowedipaddr);
#taken from a Perl tutorial somewhere a million years ago so direct reference escapes me.
sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
defined( my $pid = fork ) or die "Can't fork: $!";
#setsid - from McMaster's salvia;
if( $pid != 0 ) {
open( PIDFILE, '>/var/run/nagzillad.pid' );
print PIDFILE "$pid\n";
close(PIDFILE);
chown $uid, 0, "/var/run/nagzillad.pid";
chmod oct("0644"), "/var/run/nagzillad.pid";
# Change user ID - automagically
my $uid = ( getpwnam('nobody') )[2];
$> = $uid;
exit(0);
}
setsid or die "Can't start a new session: $!";
umask 0;
}
if ($daemon eq 1) {
&daemonize;
# Change user ID - automagically
my $uid = ( getpwnam('nobody') )[2];
$> = $uid;
}
#Let's make us a socket
$local = IO::Socket::INET->new(
Proto => 'tcp',
LocalAddr => $bindaddr,
LocalPort => $bindport,
Reuse => 1
) or die "$!";
$local->listen(); #Tell our socket to listen
#This is on by default with newer versions of IO::Socket but for bc let's turn it on anyway
$local->autoflush(1);
if ($to_log eq 1) {
$log->write( "Nagzillad Server Started", 5 );
}
#Start Jabber Stuff
# Creates a new connection to the jabber server
my $connection = Net::Jabber::Client->new( debugLevel => $jabberdebug );
$connection->Connect(
"hostname" => $jabberserver,
"port" => $jabberport,
"tls" => $jabbertls,
"ssl" => $jabberssl
) or die "Cannot connect ($!)\n"; #Return an error on failure
my @result;
if ($jabbersasl) {
@result = $connection->AuthSend(
"username" => $jabberuser,
"password" => $jabberpass,
"resource" => $jabberresource
);
} else {
@result = $connection->AuthIQAuth(
"username" => $jabberuser,
"password" => $jabberpass,
"resource" => $jabberresource
);
}
if ($result[0] ne "ok") {
#Send an auth request, return on failure
die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}
#Allow the daemon to hang out in as many rooms as needed (defined in config file)
#Depending on your Jabber server setup specifying a non-existent room will create that room
foreach $confs (@confrooms) {
my $room = $connection->MUCJoin(
room => "$confs",
server => "$confserver", #Conference server
nick => "$confnick"
); #Join a room
}
$readable_handles = new IO::Select();
$readable_handles->add($local);
while (1) {
($new_readable) = IO::Select->select( $readable_handles, undef, undef, undef );
foreach $sock (@$new_readable) {
if ($sock == $local) {
$new_sock = $sock->accept();
my $client_name = $new_sock->peeraddr;
$ip = inet_ntoa($client_name);
next if not defined $new_sock;
# check if the new peer's IP address is permitted via
# the AllowedIPAddr conf statement.
if ($check_access->($ip)) {
$log->write("accepted connection from $ip",1);
$readable_handles->add($new_sock);
} else {
$log->write("rejected connection from $ip - not in AllowedIPAddr",5);
close $new_sock;
}
} else {
$buf = <$sock>;
$readable_handles->remove($sock);
close $sock;
if ($buf) {
my ( $style, $roomy, $mess ) = split( /\^/, $buf, 3 );
my $message = Net::Jabber::Message->new();
if ($style eq "room") {
$message->SetMessage(
"type" => 'groupchat',
"to" => $roomy =~ /@/ ? $roomy : "$roomy\@$confserver",
"type" => 'chat',
"body" => $mess
);
}
else {
$message->SetMessage(
"to" => $roomy =~ /@/ ? $roomy: "$roomy\@$jabberserver",
"subject" => "Monitoring Alert",
"type" => 'chat',
"body" => "$mess"
);
}
#Send message from STDIN -- probably should add some error handling
#There is some bug in at least ejabberd that causes messages to
#be sent "offline". They get flushed on nagzilla restart
#I don't know of a good way to check if this is happening yet
#More to come - BM
$connection->Send($message);
if ($to_log eq 1) {
$log->write( "--$mess-- sent to $roomy from $ip", 5 );
}
}
}
}
#Creates a sleep timer so many messages can be handled without issue
sleep(MAXWAIT);
}
./nagzilla/patches/0000755000175000017500000000000011207375262014624 5ustar billfordbillford./nagzilla/patches/steve.patch0000600000175000017500000002441511207375262016771 0ustar billfordbillforddiff -ruN ../nagzilla-1.5.5-pre/nagzillad.pl ./nagzillad.pl
--- ../nagzilla-1.5.5-pre/nagzillad.pl 2009-05-27 19:56:52.000000000 +0000
+++ ./nagzillad.pl 2009-05-27 22:22:48.000000000 +0000
@@ -5,7 +5,6 @@
#License: See LICENSE file GPL v2
#Nagzilla Jabber Relay Bot Server
-
#import our required Perl modules
require Config::Simple;
require Data::Dumper;
@@ -13,154 +12,199 @@
use IO::Socket;
use IO::Socket::INET;
use IO::Select;
-use Net::Jabber qw(Client) ;
-use Net::Jabber qw(Message) ;
-use Net::Jabber qw(Protocol) ;
-use Net::Jabber qw(Presence) ;
+use Net::Jabber qw(Client);
+use Net::Jabber qw(Message);
+use Net::Jabber qw(Protocol);
+use Net::Jabber qw(Presence);
-#bring in our configuration variables
$CONFDIR = "/etc/nagzillad";
+
# DO NOT EDIT ANYTHING BEYOND THIS POINT!!
do "$CONFDIR/nagzillad-config.pl";
-my $log = new Log::LogLite($LOG_DIRECTORY."/nagzillad.log", $ERROR_LOG_LEVEL);
+my $log = new Log::LogLite( $LOG_DIRECTORY . "/nagzillad.log", $ERROR_LOG_LEVEL );
+
+# make_access_checker - returns a function which checks if an IP address
+# should be allowed to connect to this nagzillad.
+#
+# It takes a reference to an an array of IP addresses (dotted quad strings).
+#
+# It returns a function which takes an IP address (also a dotted quad
+# string). That function will return 1 if the IP address is allowed and
+# undef if it isn't.
+#
+sub make_access_checker {
+ my $ok_addrs = shift;
+ my %ok_addr_set = map { $_ => 1 } @{$ok_addrs};
+ return sub {
+ my $addr = shift;
+ return $ok_addr_set{$addr};
+ }
+}
+
+my $check_access = make_access_checker(\@allowedipaddr);
-#taken from a Perl tutorial somewhere a million years ago so direct reference escapes me.
+#taken from a Perl tutorial somewhere a million years ago so direct reference escapes me.
sub daemonize {
- chdir '/' or die "Can't chdir to /: $!";
- open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
- open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
- open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
- defined(my $pid = fork) or die "Can't fork: $!";
- #setsid - from McMaster's salvia;
- if ($pid != 0)
- {
- open (PIDFILE, '>/var/run/nagzillad.pid');
- print PIDFILE "$pid\n";
- close (PIDFILE);
- chown $uid, 0, "/var/run/nagzillad.pid";
- chmod oct("0644"), "/var/run/nagzillad.pid";
+ chdir '/' or die "Can't chdir to /: $!";
+ open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
+ open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
+ open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
+ defined( my $pid = fork ) or die "Can't fork: $!";
+
+ #setsid - from McMaster's salvia;
+ if( $pid != 0 ) {
+ open( PIDFILE, '>/var/run/nagzillad.pid' );
+ print PIDFILE "$pid\n";
+ close(PIDFILE);
+ chown $uid, 0, "/var/run/nagzillad.pid";
+ chmod oct("0644"), "/var/run/nagzillad.pid";
+
# Change user ID - automagically
- my $uid = (getpwnam('nobody'))[2];
+ my $uid = ( getpwnam('nobody') )[2];
$> = $uid;
- exit(0);
- }
- setsid or die "Can't start a new session: $!";
- umask 0;
+ exit(0);
+ }
+ setsid or die "Can't start a new session: $!";
+ umask 0;
}
-if ($daemon eq 1)
-{
-&daemonize;
-# Change user ID - automagically
-my $uid = (getpwnam('nobody'))[2];
-$> = $uid;
-}
+if ($daemon eq 1) {
+ &daemonize;
+ # Change user ID - automagically
+ my $uid = ( getpwnam('nobody') )[2];
+ $> = $uid;
+}
#Let's make us a socket
-$local = IO::Socket::INET->new( Proto => 'tcp',
- LocalAddr => $bindaddr,
- LocalPort => $bindport,
- Reuse => 1
- ) or die "$!";
-$local->listen(); #Tell our socket to listen
-$local->autoflush(1); #This is on by default with newer versions of IO::Socket but for bc let's turn it on anyway
-
-if ($to_log eq 1) {
-
-$log->write("Nagzillad Server Started", 5);
+$local = IO::Socket::INET->new(
+ Proto => 'tcp',
+ LocalAddr => $bindaddr,
+ LocalPort => $bindport,
+ Reuse => 1
+) or die "$!";
+$local->listen(); #Tell our socket to listen
+#This is on by default with newer versions of IO::Socket but for bc let's turn it on anyway
+$local->autoflush(1);
+if ($to_log eq 1) {
+ $log->write( "Nagzillad Server Started", 5 );
}
-
#Start Jabber Stuff
- my $connection = Net::Jabber::Client -> new( debugLevel => $jabberdebug ); #Creates a new connection to the jabber server
- $connection -> Connect( "hostname" => $jabberserver, "port" => $jabberport, "tls" => $jabbertls, "ssl" => $jabberssl ) or die "Cannot connect ($!)\n"; #Return an error on failure
+# Creates a new connection to the jabber server
+my $connection = Net::Jabber::Client->new( debugLevel => $jabberdebug );
+$connection->Connect(
+ "hostname" => $jabberserver,
+ "port" => $jabberport,
+ "tls" => $jabbertls,
+ "ssl" => $jabberssl
+) or die "Cannot connect ($!)\n"; #Return an error on failure
+
+my @result;
+if ($jabbersasl) {
+ @result = $connection->AuthSend(
+ "username" => $jabberuser,
+ "password" => $jabberpass,
+ "resource" => $jabberresource
+ );
+
+} else {
+ @result = $connection->AuthIQAuth(
+ "username" => $jabberuser,
+ "password" => $jabberpass,
+ "resource" => $jabberresource
+ );
+}
+
+if ($result[0] ne "ok") {
+ #Send an auth request, return on failure
+ die "Ident/Auth with server failed: $result[0] - $result[1]\n";
+}
- my @result;
- if ( $jabbersasl ) {
- @result = $connection->AuthSend( "username" => $jabberuser, "password" => $jabberpass, "resource" => $jabberresource );
-
- }
- else {
- @result = $connection->AuthIQAuth( "username" => $jabberuser, "password" => $jabberpass, "resource" => $jabberresource );
-
- }
-
- if ($result[0] ne "ok") {
- die "Ident/Auth with server failed: $result[0] - $result[1]\n"; #Send an auth request, return on failure
- }
#Allow the daemon to hang out in as many rooms as needed (defined in config file)
#Depending on your Jabber server setup specifying a non-existent room will create that room
foreach $confs (@confrooms) {
-
- my $room = $connection->MUCJoin(room=>"$confs",
- server=>"$confserver", #Conference server
- nick=>"$confnick"); #Join a room
+ my $room = $connection->MUCJoin(
+ room => "$confs",
+ server => "$confserver", #Conference server
+ nick => "$confnick"
+ ); #Join a room
}
$readable_handles = new IO::Select();
$readable_handles->add($local);
while (1) {
- ($new_readable) = IO::Select->select($readable_handles, undef, undef, undef);
+ ($new_readable) = IO::Select->select( $readable_handles, undef, undef, undef );
+
+ foreach $sock (@$new_readable) {
+ if ($sock == $local) {
+ $new_sock = $sock->accept();
+ my $client_name = $new_sock->peeraddr;
+ $ip = inet_ntoa($client_name);
+
+ next if not defined $new_sock;
+
+ # check if the new peer's IP address is permitted via
+ # the AllowedIPAddr conf statement.
+ if ($check_access->($ip)) {
+ $log->write("accepted connection from $ip",1);
+ $readable_handles->add($new_sock);
+ } else {
+ $log->write("rejected connection from $ip - not in AllowedIPAddr",5);
+ close $new_sock;
+ }
+ } else {
+ $buf = <$sock>;
+
+ $readable_handles->remove($sock);
+ close $sock;
+
+ if ($buf) {
+
+ my ( $style, $roomy, $mess ) = split( /\^/, $buf, 3 );
+
+ my $message = Net::Jabber::Message->new();
+ if ($style eq "room") {
+ $message->SetMessage(
+ "type" => 'groupchat',
+ "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$confserver",
+ "type" => 'chat',
+ "body" => $mess
+ );
+
+ }
+ else {
+ $message->SetMessage(
+ "to" => $roomy =~ /@/ ? $roomy: "$roomy\@$jabberserver",
+ "subject" => "Monitoring Alert",
+ "type" => 'chat',
+ "body" => "$mess"
+ );
+
+ }
+
+ #Send message from STDIN -- probably should add some error handling
+ #There is some bug in at least ejabberd that causes messages to
+ #be sent "offline". They get flushed on nagzilla restart
+ #I don't know of a good way to check if this is happening yet
+ #More to come - BM
+ $connection->Send($message);
+
+ if ($to_log eq 1) {
+ $log->write( "--$mess-- sent to $roomy from $ip", 5 );
-foreach $sock (@$new_readable) {
- if ($sock == $local){
- $new_sock = $sock->accept();
- my $client_name = $new_sock->peeraddr;
- $ip = inet_ntoa($client_name);
- #print "$ip \n";
- next if not defined $new_sock;
- $readable_handles->add($new_sock);
- }else{
- if (grep {$_ eq $ip} @allowedipaddr) {
-
- $buf = <$sock>;
-
- $readable_handles->remove($sock);
- close $sock;
-
- if ($buf) {
-
-my ($style, $roomy, $mess) = split(/\^/, $buf, 3);
-
- my $message = Net::Jabber::Message->new();
- if ($style eq "room") {
- $message->SetMessage( "type" => 'groupchat',
- "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$confserver",
- "type" => 'chat',
- "body" => $mess );
-
- } else {
- $message->SetMessage ( "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$jabberserver",
- "subject" => "Monitoring Alert",
- "type" => 'chat',
- "body" => "$mess" );
-
- }
- $connection->Send($message); #Send message from STDIN -- probably should add some error handling
- #There is some bug in at least ejabberd that causes messages to
- #be sent "offline". They get flushed on nagzilla restart
- #I don't know of a good way to check if this is happening yet
- #More to come - BM
-
- if ($to_log eq 1) {
- $log->write("--$mess-- sent to $roomy from $ip", 5);
-
+ }
+ }
}
-
-}
-
- }
-}
-}
- sleep (MAXWAIT); #Creates a sleep timer so many messages can be handled without issue
-
}
-
\ No newline at end of file
+ #Creates a sleep timer so many messages can be handled without issue
+ sleep(MAXWAIT);
+}
+
diff -ruN ../nagzilla-1.5.5-pre/README ./README
--- ../nagzilla-1.5.5-pre/README 2009-05-27 20:02:59.000000000 +0000
+++ ./README 2009-05-27 21:18:06.000000000 +0000
@@ -23,10 +23,10 @@
IO::Socket
IO::Socket::INET
- Net::Jabber
- Config::Simple
+ Net::Jabber (Ubuntu package: libnet-jabber-perl)
+ Config::Simple (Ubuntu package: libconfig-simple-perl)
Data::Dumper
- Log::LogLite
+ Log::LogLite (Ubuntu package: liblog-loglite-perl)
Nagzillad Installation
./nagzilla/patches/01_chat-message-fix0000644000175000017500000000165311207134665020201 0ustar billfordbillfordAuthor: Gerfried Fuchs vim:ft=diff:
Description: Allows handing over complete JIDs for room and chat types
Index: nagzilla-1.5.4-2/nagzilla/nagzillad.pl
===================================================================
--- nagzilla-1.5.4-2.orig/nagzilla/nagzillad.pl
+++ nagzilla-1.5.4-2/nagzilla/nagzillad.pl
@@ -116,12 +116,12 @@ $mess = "@clientin[2]";
my $message = Net::Jabber::Message->new();
if ($style eq "room") {
$message->SetMessage( "type" => 'groupchat',
- "to" => "$roomy\@$confserver",
+ "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$confserver",
"type" => 'chat',
"body" => "$mess" );
} else {
- $message->SetMessage ( "to" => "$roomy\@$jabberserver",
+ $message->SetMessage ( "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$jabberserver",
"subject" => "Monitoring Alert",
"type" => 'chat',
"body" => "$mess" );
./nagzilla/patches/02_allow-carret-in-message0000644000175000017500000000105611207134665021474 0ustar billfordbillfordAuthor: Gerfried Fuchs vim:ft=diff:
Description: Allow ^ being part of the message instead of message cut point
Index: nagzilla-1.5.4-2/nagzilla/nagzillad.pl
===================================================================
--- nagzilla-1.5.4-2.orig/nagzilla/nagzillad.pl
+++ nagzilla-1.5.4-2/nagzilla/nagzillad.pl
@@ -108,7 +108,7 @@ while ($addr = $local->accept() ) {
while (<$addr>) {
-@clientin = split(/\^/, $_);
+@clientin = split(/\^/, $_, 3);
$style = "@clientin[0]";
$roomy = "@clientin[1]";
$mess = "@clientin[2]";
./nagzilla/patches/.svn/0000755000175000017500000000000011207562104015501 5ustar billfordbillford./nagzilla/patches/.svn/format0000444000175000017500000000000211207134665016711 0ustar billfordbillford9
./nagzilla/patches/.svn/prop-base/0000755000175000017500000000000011207134665017400 5ustar billfordbillford./nagzilla/patches/.svn/props/0000755000175000017500000000000011207134665016653 5ustar billfordbillford./nagzilla/patches/.svn/entries0000444000175000017500000000127411207375324017105 0ustar billfordbillford9
dir
2
https://nagzilla.googlecode.com/svn/trunk/patches
https://nagzilla.googlecode.com/svn
2009-05-27T02:54:24.631590Z
2
billford
svn:special svn:externals svn:needs-lock
8473c688-9fee-11dd-a5cd-697bfd0a0cef
02_allow-carret-in-message
file
2009-05-27T03:55:33.000000Z
2aaeef7e1378802e270f2c45a890f36d
2009-05-27T02:54:24.631590Z
2
billford
558
steve.patch
file
7
2009-05-28T02:45:06.000000Z
f2e76371ad93f6dcb1e41ff5824f2c15
2009-05-28T02:45:40.797661Z
7
billford
10509
01_chat-message-fix
file
2009-05-27T03:55:33.000000Z
c08c123e9e8e2aef7c809126e7bcf8cd
2009-05-27T02:54:24.631590Z
2
billford
939
./nagzilla/patches/.svn/all-wcprops0000444000175000017500000000061611207375324017676 0ustar billfordbillfordK 25
svn:wc:ra_dav:version-url
V 29
/svn/!svn/ver/2/trunk/patches
END
02_allow-carret-in-message
K 25
svn:wc:ra_dav:version-url
V 56
/svn/!svn/ver/2/trunk/patches/02_allow-carret-in-message
END
steve.patch
K 25
svn:wc:ra_dav:version-url
V 41
/svn/!svn/ver/7/trunk/patches/steve.patch
END
01_chat-message-fix
K 25
svn:wc:ra_dav:version-url
V 49
/svn/!svn/ver/2/trunk/patches/01_chat-message-fix
END
./nagzilla/patches/.svn/text-base/0000755000175000017500000000000011207375324017403 5ustar billfordbillford./nagzilla/patches/.svn/text-base/02_allow-carret-in-message.svn-base0000444000175000017500000000105611207134665025767 0ustar billfordbillfordAuthor: Gerfried Fuchs vim:ft=diff:
Description: Allow ^ being part of the message instead of message cut point
Index: nagzilla-1.5.4-2/nagzilla/nagzillad.pl
===================================================================
--- nagzilla-1.5.4-2.orig/nagzilla/nagzillad.pl
+++ nagzilla-1.5.4-2/nagzilla/nagzillad.pl
@@ -108,7 +108,7 @@ while ($addr = $local->accept() ) {
while (<$addr>) {
-@clientin = split(/\^/, $_);
+@clientin = split(/\^/, $_, 3);
$style = "@clientin[0]";
$roomy = "@clientin[1]";
$mess = "@clientin[2]";
./nagzilla/patches/.svn/text-base/01_chat-message-fix.svn-base0000444000175000017500000000165311207134665024474 0ustar billfordbillfordAuthor: Gerfried Fuchs vim:ft=diff:
Description: Allows handing over complete JIDs for room and chat types
Index: nagzilla-1.5.4-2/nagzilla/nagzillad.pl
===================================================================
--- nagzilla-1.5.4-2.orig/nagzilla/nagzillad.pl
+++ nagzilla-1.5.4-2/nagzilla/nagzillad.pl
@@ -116,12 +116,12 @@ $mess = "@clientin[2]";
my $message = Net::Jabber::Message->new();
if ($style eq "room") {
$message->SetMessage( "type" => 'groupchat',
- "to" => "$roomy\@$confserver",
+ "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$confserver",
"type" => 'chat',
"body" => "$mess" );
} else {
- $message->SetMessage ( "to" => "$roomy\@$jabberserver",
+ $message->SetMessage ( "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$jabberserver",
"subject" => "Monitoring Alert",
"type" => 'chat',
"body" => "$mess" );
./nagzilla/patches/.svn/text-base/steve.patch.svn-base0000444000175000017500000002441511207375323023272 0ustar billfordbillforddiff -ruN ../nagzilla-1.5.5-pre/nagzillad.pl ./nagzillad.pl
--- ../nagzilla-1.5.5-pre/nagzillad.pl 2009-05-27 19:56:52.000000000 +0000
+++ ./nagzillad.pl 2009-05-27 22:22:48.000000000 +0000
@@ -5,7 +5,6 @@
#License: See LICENSE file GPL v2
#Nagzilla Jabber Relay Bot Server
-
#import our required Perl modules
require Config::Simple;
require Data::Dumper;
@@ -13,154 +12,199 @@
use IO::Socket;
use IO::Socket::INET;
use IO::Select;
-use Net::Jabber qw(Client) ;
-use Net::Jabber qw(Message) ;
-use Net::Jabber qw(Protocol) ;
-use Net::Jabber qw(Presence) ;
+use Net::Jabber qw(Client);
+use Net::Jabber qw(Message);
+use Net::Jabber qw(Protocol);
+use Net::Jabber qw(Presence);
-#bring in our configuration variables
$CONFDIR = "/etc/nagzillad";
+
# DO NOT EDIT ANYTHING BEYOND THIS POINT!!
do "$CONFDIR/nagzillad-config.pl";
-my $log = new Log::LogLite($LOG_DIRECTORY."/nagzillad.log", $ERROR_LOG_LEVEL);
+my $log = new Log::LogLite( $LOG_DIRECTORY . "/nagzillad.log", $ERROR_LOG_LEVEL );
+
+# make_access_checker - returns a function which checks if an IP address
+# should be allowed to connect to this nagzillad.
+#
+# It takes a reference to an an array of IP addresses (dotted quad strings).
+#
+# It returns a function which takes an IP address (also a dotted quad
+# string). That function will return 1 if the IP address is allowed and
+# undef if it isn't.
+#
+sub make_access_checker {
+ my $ok_addrs = shift;
+ my %ok_addr_set = map { $_ => 1 } @{$ok_addrs};
+ return sub {
+ my $addr = shift;
+ return $ok_addr_set{$addr};
+ }
+}
+
+my $check_access = make_access_checker(\@allowedipaddr);
-#taken from a Perl tutorial somewhere a million years ago so direct reference escapes me.
+#taken from a Perl tutorial somewhere a million years ago so direct reference escapes me.
sub daemonize {
- chdir '/' or die "Can't chdir to /: $!";
- open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
- open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
- open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
- defined(my $pid = fork) or die "Can't fork: $!";
- #setsid - from McMaster's salvia;
- if ($pid != 0)
- {
- open (PIDFILE, '>/var/run/nagzillad.pid');
- print PIDFILE "$pid\n";
- close (PIDFILE);
- chown $uid, 0, "/var/run/nagzillad.pid";
- chmod oct("0644"), "/var/run/nagzillad.pid";
+ chdir '/' or die "Can't chdir to /: $!";
+ open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
+ open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
+ open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
+ defined( my $pid = fork ) or die "Can't fork: $!";
+
+ #setsid - from McMaster's salvia;
+ if( $pid != 0 ) {
+ open( PIDFILE, '>/var/run/nagzillad.pid' );
+ print PIDFILE "$pid\n";
+ close(PIDFILE);
+ chown $uid, 0, "/var/run/nagzillad.pid";
+ chmod oct("0644"), "/var/run/nagzillad.pid";
+
# Change user ID - automagically
- my $uid = (getpwnam('nobody'))[2];
+ my $uid = ( getpwnam('nobody') )[2];
$> = $uid;
- exit(0);
- }
- setsid or die "Can't start a new session: $!";
- umask 0;
+ exit(0);
+ }
+ setsid or die "Can't start a new session: $!";
+ umask 0;
}
-if ($daemon eq 1)
-{
-&daemonize;
-# Change user ID - automagically
-my $uid = (getpwnam('nobody'))[2];
-$> = $uid;
-}
+if ($daemon eq 1) {
+ &daemonize;
+ # Change user ID - automagically
+ my $uid = ( getpwnam('nobody') )[2];
+ $> = $uid;
+}
#Let's make us a socket
-$local = IO::Socket::INET->new( Proto => 'tcp',
- LocalAddr => $bindaddr,
- LocalPort => $bindport,
- Reuse => 1
- ) or die "$!";
-$local->listen(); #Tell our socket to listen
-$local->autoflush(1); #This is on by default with newer versions of IO::Socket but for bc let's turn it on anyway
-
-if ($to_log eq 1) {
-
-$log->write("Nagzillad Server Started", 5);
+$local = IO::Socket::INET->new(
+ Proto => 'tcp',
+ LocalAddr => $bindaddr,
+ LocalPort => $bindport,
+ Reuse => 1
+) or die "$!";
+$local->listen(); #Tell our socket to listen
+#This is on by default with newer versions of IO::Socket but for bc let's turn it on anyway
+$local->autoflush(1);
+if ($to_log eq 1) {
+ $log->write( "Nagzillad Server Started", 5 );
}
-
#Start Jabber Stuff
- my $connection = Net::Jabber::Client -> new( debugLevel => $jabberdebug ); #Creates a new connection to the jabber server
- $connection -> Connect( "hostname" => $jabberserver, "port" => $jabberport, "tls" => $jabbertls, "ssl" => $jabberssl ) or die "Cannot connect ($!)\n"; #Return an error on failure
+# Creates a new connection to the jabber server
+my $connection = Net::Jabber::Client->new( debugLevel => $jabberdebug );
+$connection->Connect(
+ "hostname" => $jabberserver,
+ "port" => $jabberport,
+ "tls" => $jabbertls,
+ "ssl" => $jabberssl
+) or die "Cannot connect ($!)\n"; #Return an error on failure
+
+my @result;
+if ($jabbersasl) {
+ @result = $connection->AuthSend(
+ "username" => $jabberuser,
+ "password" => $jabberpass,
+ "resource" => $jabberresource
+ );
+
+} else {
+ @result = $connection->AuthIQAuth(
+ "username" => $jabberuser,
+ "password" => $jabberpass,
+ "resource" => $jabberresource
+ );
+}
+
+if ($result[0] ne "ok") {
+ #Send an auth request, return on failure
+ die "Ident/Auth with server failed: $result[0] - $result[1]\n";
+}
- my @result;
- if ( $jabbersasl ) {
- @result = $connection->AuthSend( "username" => $jabberuser, "password" => $jabberpass, "resource" => $jabberresource );
-
- }
- else {
- @result = $connection->AuthIQAuth( "username" => $jabberuser, "password" => $jabberpass, "resource" => $jabberresource );
-
- }
-
- if ($result[0] ne "ok") {
- die "Ident/Auth with server failed: $result[0] - $result[1]\n"; #Send an auth request, return on failure
- }
#Allow the daemon to hang out in as many rooms as needed (defined in config file)
#Depending on your Jabber server setup specifying a non-existent room will create that room
foreach $confs (@confrooms) {
-
- my $room = $connection->MUCJoin(room=>"$confs",
- server=>"$confserver", #Conference server
- nick=>"$confnick"); #Join a room
+ my $room = $connection->MUCJoin(
+ room => "$confs",
+ server => "$confserver", #Conference server
+ nick => "$confnick"
+ ); #Join a room
}
$readable_handles = new IO::Select();
$readable_handles->add($local);
while (1) {
- ($new_readable) = IO::Select->select($readable_handles, undef, undef, undef);
+ ($new_readable) = IO::Select->select( $readable_handles, undef, undef, undef );
+
+ foreach $sock (@$new_readable) {
+ if ($sock == $local) {
+ $new_sock = $sock->accept();
+ my $client_name = $new_sock->peeraddr;
+ $ip = inet_ntoa($client_name);
+
+ next if not defined $new_sock;
+
+ # check if the new peer's IP address is permitted via
+ # the AllowedIPAddr conf statement.
+ if ($check_access->($ip)) {
+ $log->write("accepted connection from $ip",1);
+ $readable_handles->add($new_sock);
+ } else {
+ $log->write("rejected connection from $ip - not in AllowedIPAddr",5);
+ close $new_sock;
+ }
+ } else {
+ $buf = <$sock>;
+
+ $readable_handles->remove($sock);
+ close $sock;
+
+ if ($buf) {
+
+ my ( $style, $roomy, $mess ) = split( /\^/, $buf, 3 );
+
+ my $message = Net::Jabber::Message->new();
+ if ($style eq "room") {
+ $message->SetMessage(
+ "type" => 'groupchat',
+ "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$confserver",
+ "type" => 'chat',
+ "body" => $mess
+ );
+
+ }
+ else {
+ $message->SetMessage(
+ "to" => $roomy =~ /@/ ? $roomy: "$roomy\@$jabberserver",
+ "subject" => "Monitoring Alert",
+ "type" => 'chat',
+ "body" => "$mess"
+ );
+
+ }
+
+ #Send message from STDIN -- probably should add some error handling
+ #There is some bug in at least ejabberd that causes messages to
+ #be sent "offline". They get flushed on nagzilla restart
+ #I don't know of a good way to check if this is happening yet
+ #More to come - BM
+ $connection->Send($message);
+
+ if ($to_log eq 1) {
+ $log->write( "--$mess-- sent to $roomy from $ip", 5 );
-foreach $sock (@$new_readable) {
- if ($sock == $local){
- $new_sock = $sock->accept();
- my $client_name = $new_sock->peeraddr;
- $ip = inet_ntoa($client_name);
- #print "$ip \n";
- next if not defined $new_sock;
- $readable_handles->add($new_sock);
- }else{
- if (grep {$_ eq $ip} @allowedipaddr) {
-
- $buf = <$sock>;
-
- $readable_handles->remove($sock);
- close $sock;
-
- if ($buf) {
-
-my ($style, $roomy, $mess) = split(/\^/, $buf, 3);
-
- my $message = Net::Jabber::Message->new();
- if ($style eq "room") {
- $message->SetMessage( "type" => 'groupchat',
- "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$confserver",
- "type" => 'chat',
- "body" => $mess );
-
- } else {
- $message->SetMessage ( "to" => $roomy =~ /@/ ? $roomy : "$roomy\@$jabberserver",
- "subject" => "Monitoring Alert",
- "type" => 'chat',
- "body" => "$mess" );
-
- }
- $connection->Send($message); #Send message from STDIN -- probably should add some error handling
- #There is some bug in at least ejabberd that causes messages to
- #be sent "offline". They get flushed on nagzilla restart
- #I don't know of a good way to check if this is happening yet
- #More to come - BM
-
- if ($to_log eq 1) {
- $log->write("--$mess-- sent to $roomy from $ip", 5);
-
+ }
+ }
}
-
-}
-
- }
-}
-}
- sleep (MAXWAIT); #Creates a sleep timer so many messages can be handled without issue
-
}
-
\ No newline at end of file
+ #Creates a sleep timer so many messages can be handled without issue
+ sleep(MAXWAIT);
+}
+
diff -ruN ../nagzilla-1.5.5-pre/README ./README
--- ../nagzilla-1.5.5-pre/README 2009-05-27 20:02:59.000000000 +0000
+++ ./README 2009-05-27 21:18:06.000000000 +0000
@@ -23,10 +23,10 @@
IO::Socket
IO::Socket::INET
- Net::Jabber
- Config::Simple
+ Net::Jabber (Ubuntu package: libnet-jabber-perl)
+ Config::Simple (Ubuntu package: libconfig-simple-perl)
Data::Dumper
- Log::LogLite
+ Log::LogLite (Ubuntu package: liblog-loglite-perl)
Nagzillad Installation
./nagzilla/patches/.svn/tmp/0000755000175000017500000000000011207375324016307 5ustar billfordbillford./nagzilla/patches/.svn/tmp/prop-base/0000755000175000017500000000000011207134665020200 5ustar billfordbillford./nagzilla/patches/.svn/tmp/props/0000755000175000017500000000000011207134665017453 5ustar billfordbillford./nagzilla/patches/.svn/tmp/text-base/0000755000175000017500000000000011207375324020203 5ustar billfordbillford./nagzilla/README0000755000175000017500000000556411207373742014073 0ustar billfordbillford10/20/2008 -- Nagzilla client/server
01/10/2009 -- Updated
05/26/2009 -- Updated
05/27/2009 -- Updated
DISCLAIMER: This is provided AS-IS with no warranty expressed or implied. I nor the company are responsible for anything you do with it so don't expect us to be.
LICENSE: GPL v2. See LICENSE File
Overview:
Nagzilla was designed to be a Jabber relay "bot" in that it sits quietly in a room until it gets a message to relay to either a chatroom or a person. The early work was based on several simple examples out on the internets but didn't quite meet our needs. Namely they would just keep logging into a room every time they had something to say. That forced us to make it a daemon. This also allows us to now get nagzilla alerts from various systems and event creators. Nagzillac (the client program") accepts any string input and makes into a Jabber message. This should work with Google Talk (as it's Jabber based) but
that's not been tested. The only platform this has been tested on is ejabberd running on Ubuntu. I have no doubts it SHOULD work on other Jabber/Linux/Perl platforms as well.
Nagzilla provides some rudimentary security. You have to have your IP address defined in nagzillad.cfg to send messages but on a local LAN spoofing is trivial. You should still use your firewall wisely in this case and allow access only from those clients who should have it.
Installation:
Nagzilla consists of two components nagzillad (the server) and nagzillac (the client). They do not have to live on the same machine at all but require the
same perl modules be installed.
Required Perl Modules:
IO::Socket
IO::Socket::INET
Net::Jabber (Ubuntu package: libnet-jabber-perl)
Config::Simple (Ubuntu package: libconfig-simple-perl)
Data::Dumper (Ubuntu Package: libdata-dumper-simple-perl)
Log::LogLite (Ubuntu package: liblog-loglite-perl)
Nagzillad Installation
mkdir /etc/nagzillad/
cp nazillad.cfg and nagzillad-config.pl to /etc/nagzillad
cp nagzillad.pl to /usr/local/sbin (or wherever on your system you want it to live)
Edit nagzillad.cfg to suit your needs (file should be self-explanatory)
start nagzillad.pl with & or add an init script (next version?)
Nagzillac Installation
mkdir /etc/nagzillac
cp nagzillac.cfg and nagzillac-config.pl to /etc/nagzillac
cp nagzillac.pl to /usr/local/bin (or wherever on your system you want it to live)
Edit nagzillac.cfg to suit your needs
Make the magic happen:
nagzillac.pl "TYPE^TO^MESSAGE"
TYPE: This can be either 'room' or 'chat' -- room == a chatroom and chat == an individual
TO: What room or person to send to
MESSAGE: Your message (which should avoid having ^ in it)
EXAMPLE: nagzillac.pl "room^chatroom^Hi guys a server is down in some far away place"
That's it. Not a bad little hack if you have to monitor stuff and sit in IM all day (or a chat room).
./nagzilla/TODO0000755000175000017500000000327011207374677013703 0ustar billfordbillford
nagzillad should require some sort of authentication with its clients (perhaps ssl certs or shared secrets, oh my) - started 5/27/09 -- currently only IP of client is checked
nagzillad should accept rawxml messages (patch provided from rhonda@debian.at but needs improvement)
nagzillad should offer browser support (still have some thinking to do about this)
nagzillad should support SSL to it's client (nagzillac)
Added some stress testing bash scripts, nothing fancy will improve later -- initially completed 5/26/2009
nagzillad should handle multiple connections -- completed and tested with 15000 multiple connections -- 05/26/2009
nagzillad needs to read from a config file -- completed -- 09/28/08
nagzillad should be able to sit in multiple rooms without issue -- proof of concept proven - completed --10/1/08
nagzillad should NOT run as root - add a check at startup for this -- completed -- 01/09/09
nagzillad /nagzillac communications should be encrypted -- Not sure this will happen in this release
nagzillad should be able to write messages to a log file / maybe a web view? -- logs for messages completed -- 01/09/09
nagzilla should be renamed to nagzillac - completed - 09/28/08
nagzillac should take several command line arguments - completed - 10/20/08
a) server to connect to
b) port to connect to
c) room/person to send message to
d) message (must escape control characters)
nagzillac will stay command line based as to allow for easier "scriptability" with zenoss and nagios alerts
This should allow for messaging of whoever for whatever purpose
General error checking should be improved -- connectivity, presence and room tests
Code needs to be tidied up -- perltidy FTW -- thanks steve!
./nagzilla/utilities/0000755000175000017500000000000011207134665015210 5ustar billfordbillford./nagzilla/utilities/stresstest2.sh0000755000175000017500000000016511207134665020056 0ustar billfordbillford#!/bin/bash
i="0"
while [ $i -lt 1000 ]
do
/usr/local/bin/nagzillac.pl "room^test^stresstesting2"
i=$[$i+1]
done
./nagzilla/utilities/stresstest.sh0000755000175000017500000000016411207134665017773 0ustar billfordbillford#!/bin/bash
i="0"
while [ $i -lt 1000 ]
do
/usr/local/bin/nagzillac.pl "room^test^stresstesting"
i=$[$i+1]
done
./nagzilla/utilities/.svn/0000755000175000017500000000000011207562104016065 5ustar billfordbillford./nagzilla/utilities/.svn/format0000444000175000017500000000000211207134665017275 0ustar billfordbillford9
./nagzilla/utilities/.svn/prop-base/0000755000175000017500000000000011207134665017764 5ustar billfordbillford./nagzilla/utilities/.svn/prop-base/stresstest.sh.svn-base0000444000175000017500000000003511207134665024254 0ustar billfordbillfordK 14
svn:executable
V 0
END
./nagzilla/utilities/.svn/prop-base/stresstest2.sh.svn-base0000444000175000017500000000003511207134665024336 0ustar billfordbillfordK 14
svn:executable
V 0
END
./nagzilla/utilities/.svn/props/0000755000175000017500000000000011207134665017237 5ustar billfordbillford./nagzilla/utilities/.svn/entries0000444000175000017500000000104711207134665017470 0ustar billfordbillford9
dir
2
https://nagzilla.googlecode.com/svn/trunk/utilities
https://nagzilla.googlecode.com/svn
2009-05-27T02:54:24.631590Z
2
billford
svn:special svn:externals svn:needs-lock
8473c688-9fee-11dd-a5cd-697bfd0a0cef
stresstest.sh
file
2009-05-27T03:55:33.000000Z
2067bbcbf518d794fd51fb1bfd44b634
2009-05-27T02:54:24.631590Z
2
billford
has-props
116
stresstest2.sh
file
2009-05-27T03:55:33.000000Z
812fbc871501b2cec5b7d7db01b960f2
2009-05-27T02:54:24.631590Z
2
billford
has-props
117
./nagzilla/utilities/.svn/all-wcprops0000444000175000017500000000042211207134665020256 0ustar billfordbillfordK 25
svn:wc:ra_dav:version-url
V 31
/svn/!svn/ver/2/trunk/utilities
END
stresstest.sh
K 25
svn:wc:ra_dav:version-url
V 45
/svn/!svn/ver/2/trunk/utilities/stresstest.sh
END
stresstest2.sh
K 25
svn:wc:ra_dav:version-url
V 46
/svn/!svn/ver/2/trunk/utilities/stresstest2.sh
END
./nagzilla/utilities/.svn/text-base/0000755000175000017500000000000011207134665017770 5ustar billfordbillford./nagzilla/utilities/.svn/text-base/stresstest.sh.svn-base0000444000175000017500000000016411207134665024263 0ustar billfordbillford#!/bin/bash
i="0"
while [ $i -lt 1000 ]
do
/usr/local/bin/nagzillac.pl "room^test^stresstesting"
i=$[$i+1]
done
./nagzilla/utilities/.svn/text-base/stresstest2.sh.svn-base0000444000175000017500000000016511207134665024346 0ustar billfordbillford#!/bin/bash
i="0"
while [ $i -lt 1000 ]
do
/usr/local/bin/nagzillac.pl "room^test^stresstesting2"
i=$[$i+1]
done
./nagzilla/utilities/.svn/tmp/0000755000175000017500000000000011207134665016674 5ustar billfordbillford./nagzilla/utilities/.svn/tmp/prop-base/0000755000175000017500000000000011207134665020564 5ustar billfordbillford./nagzilla/utilities/.svn/tmp/props/0000755000175000017500000000000011207134665020037 5ustar billfordbillford./nagzilla/utilities/.svn/tmp/text-base/0000755000175000017500000000000011207134665020570 5ustar billfordbillford./nagzilla/VERSION0000755000175000017500000000011711207316225014241 0ustar billfordbillfordNagzilla Client/Server 1.5.5
(c) 2006-2009 Hurricane Labs, LLC
by Bill Mathews