use lib "@@LIBDIR@@";
-use Data::Dumper;
-
use Spong::AckList;
use Sys::Hostname;
+use Getopt::Long;
+use FileHandle;
use English;
-if( $ARGV[0] eq "--debug" ) { $debug = 1; shift @ARGV; }
-if( $ARGV[0] eq "--test" ) { $test = 1; shift @ARGV; }
+my %opt;
+@options = ( "help", "host=s", "service=s", "time=i", "color|status=s", "summary=s",
+ "duration=i", "message=s", "file=s", "debug", "test" );
+Getopt::Long::Configure("pass_through");
+if( ! GetOptions( \%opt, @options ) ) { &error("Incorect usage"); exit 1; }
+
+# Check usage, and read in what we are supposed to do.
+
+&help if defined $opt{'help'};
+
+my($color, $host, $service, $time, $summary, $duration) = @ARGV;
+
+if ( ! $color && defined $opt{'color'} ) { $color = $opt{'color'}; }
+if ( $color !~ /red|yellow|green/ ) {
+ &error( "Invalid status color. Must be green, yellow, or red."); exit 1;
+}
+if ( ! $host && defined $opt{'host'} ) { $host = $opt{'host'}; }
+if ( ! $host ) { &error("Host name is required"); exit 1; }
+if ( ! $service && defined $opt{'service'} ) { $service = $opt{'service'}; }
+if ( ! $service ) { &error("Service name is required"); exit -1; }
+if ( ! $time && defined $opt{'time'} ) { $time = $opt{'time'}; }
+if ( ! $time ) { &error("Time is required"); exit 1; }
+if ( ! $summary && defined $opt{'summary'} ) { $summary = $opt{'summary'}; }
+if ( ! $summary ) { warn "Summary text is required\n\n"; exit 1; }
+#if ( ! defined $opt{'message'} && ! defined $opt{'file'} ) {
+# &error("--message or --file is required"); exit 1; }
+if ( defined $opt{'message'} && defined $opt{'file'} ) {
+ &error("Only one of --message or --file can be specified"); exit 1; }
+if ( ! defined $duration ) {
+ if ( defined $opt{'duration'} ) { $duration = $opt{'duration'}; } else { $duration = 0; } }
+$debug = $opt{'debug'};
+$test = $opt{'test'};
+
+
+# Handle message file processing if necessary
+my ( $message ) = "";
+if ( $opt{'message'} ) { $message = $opt{'message'}; }
+elsif ( ! defined $opt{'file'} ) { }
+elsif ( $opt{'file'} eq '-' ) { while (<STDIN>) { $message .= $_; } }
+else {
+ my($fh) = File::Handle->new($opt{'file'});
+ if (! defined $fh ) {
+ &error("Could not open file " . $opt{'file'} );
+ exit -1;
+ }
+ while (<$fh>) { $message .= $_; }
+ undef $fh;
+}
+
+#if( $#ARGV == 4 || $#ARGV == 5) {
+# if (! defined $duration || $duration eq "") { $duration = 0; }
+#} else {
+# print STDERR "Error: Incorrect usage!\n";
+# print STDERR
+# "Usage: spong-message [--debug] color host service time message [duration]\n";
+# exit(-1);
+#}
+
$conf_file = "@@ETCDIR@@/spong.conf";
$hosts_file = "@@ETCDIR@@/spong.hosts";
$groups_file = "@@ETCDIR@@/spong.groups";
-$message_file = "@@ETCDIR@@/spong.message";
+$summary_file = "@@ETCDIR@@/spong.message";
$msgfunc_path = "@@LIBDIR@@/Spong/Message/plugins";
($HOST) = gethostbyname(&Sys::Hostname::hostname());
$HOST =~ tr/A-Z/a-z/;
# Read in the spong.message file
-require $message_file || die "Can't load $message_file: $!";
+require $summary_file || die "Can't load $summary_file: $!";
&debug( "spong.message file loaded" );
# Read in the spong.hosts file
close( HISTORY );
&debug( "message history database loaded" );
-# Check usage, and read in what we are supposed to do.
-
-if( $#ARGV == 4 || $#ARGV == 5) {
- ($color, $host, $service, $time, $message, $duration) = @ARGV;
- if (! defined $duration || $duration eq "") { $duration = 0; }
-} else {
- print STDERR "Error: Incorrect usage!\n";
- print STDERR
- "Usage: spong-message [--debug] color host service time message [duration]\n";
- exit(-1);
-}
-
# Load any acknowledgements for the host and check the message against then
$acks = new Spong::AckList($host);
print MAIL "To: $email\n";
print MAIL "Subject: spong - $color $host $service\n\n";
print MAIL scalar localtime($time), "\n";
- print MAIL "$message\n";
+ print MAIL "$summary\n";
close( MAIL );
&debug( "mail message sent to $email" );
}
print MAIL "To: $skytel\@skymail.com\n";
print MAIL "Subject: spong - $color $host $service\n\n";
print MAIL scalar localtime($time), "\n";
- print MAIL "$message\n";
+ print MAIL "$summary\n";
close( MAIL );
&debug( "skytel page sent to $skytel" );
print MAIL "\n"; # Header/Body boundry
print MAIL scalar localtime($time), "\n";
print MAIL "$color $host $service\n";
- print MAIL "$message\n";
+ print MAIL "$summary\n";
close( MAIL );
}