#!/usr/bin/perl -w ############################################################### # Script for logging automation to a Syslog server # # For public use, creator takes no responsibilities for # # any damages, misconfigs or loss of sanity resulting from # # these script(s) # ############################################################### use strict; use Net::Ping; use Net::Syslog; use Getopt::Std; use vars qw($opt_p $opt_t $opt_m); #Set an array with legal Priority values my @priVals = qw(emerg alert crit err warning notice info debug); getopts('m:p:t:'); # I prefer &getopts('f?h:u:p:', \%O) because it doesn't # set additional global vars like described in pod unless ( defined $opt_p && defined $opt_t ) { die(<<' THEOPTIONS'); Missing Options! Required: -p Can be emerg, alert, crit, err, warning, notice, info, debug -t Note: If you use spaces in your message, surround the message in quotes -m Note: this is optional, default is 127.0.0.1 THEOPTIONS } $opt_m = "127.0.0.1" unless defined $opt_m; my $pingResult = Net::Ping->new('icmp'); die ("\nSysLoggerErr:1\nCannot resolve $opt_m\n") unless $pingResult->ping($opt_m); $pingResult->close() ; for my $priV (@priVals) { last if $opt_p eq $priV; die ("Not a valid Priority, check caps as this is case sensitive!\n") if $priV eq 'debug'; next if $opt_p ne $priV; } my $syslog = new Net::Syslog(SyslogHost => $opt_m, Facility => 'syslog', Priority => $opt_p); $syslog->send("$opt_t\n") ; exit;