On 5/20/09 5:39 PM, Israel Brewster wrote:

Which is basically the same thing as hacking the Python script except
for a) having to start from scratch, and b) having to work in a language
I have little experience with :-) I was sort of hoping someone had
already done the above steps and would be willing to share :-D Oh well,
it won't take more than a couple of hours to whip the Python into shape,
and has the advantage of being self-contained, aside from some standard
Python modules (so no installing from CPAN or the like). Thanks for the
suggestion though :-)

I missed the part about Python, sorry. :D

However I wish to share with you and the rest of us this Perl script I wrote to notify Growl.

It is based on the example provided by Net::Growl. Obviously, Net::Growl is required. A small documentation is included too.

I hope it's bug free and will be useful to some of you. :)

#!/usr/bin/perl -w
# Created by Mathieu Gagné 2009

use strict;
use warnings;
use Net::Growl;
use Getopt::Long qw(:config no_ignore_case bundling);

# Default values
my $application = 'Nagios';
my $title = 'Alert';
my $message = '';
my $priority = 2;
my $sticky = 0;
my $destination = 'localhost';
my $password = '';

my $help = 0;

my $pod2usage = sub {
  # Load Pod::Usage only if needed.
  require "Pod/Usage.pm";
  import Pod::Usage;

# Declare and retreive options
  'h|help'          => \$help,
  'a|application=s' => \$application,
  't|title=s'       => \$title,
  'm|message=s'     => \$message,
  'P|priority=i'    => \$priority,
  's|sticky'        => \$sticky,
  'H|host=s'        => \$destination,
  'p|password=s'    => \$password,
) or $pod2usage->(1);

# Print help
$pod2usage->(1) if $help;

# Validate options
if ( $application eq '' ) {
  die "Error: Missing mandatory option: application\n";

if ( $title eq '' ) {
  die "Error: Missing mandatory option: title\n";

if ( $message eq '' ) {
  die "Error: Missing mandatory option: message\n";

if ( $priority eq '' ) {
  die "Error: Missing mandatory option: priority\n";

if ( $password eq '' ) {
  die "Error: Missing mandatory option: password\n";

# Main program

# Set up the Socket
my %addr = (
  PeerAddr => $destination,
  PeerPort => Net::Growl::GROWL_UDP_PORT,
  Proto    => 'udp',

my $s = IO::Socket::INET->new ( %addr ) || die "Could not create socket: $!\n";

# Register the application
my $p = Net::Growl::RegistrationPacket->new(
  application => $application,
  password    => $password,


print $s $p->payload();

# Send a notification
$p = Net::Growl::NotificationPacket->new(
  application => $application,
  title       => $title,
  description => $message,
  priority    => $priority,
  sticky      => $sticky,
  password    => $password,

print $s $p->payload();


=head1 NAME

 Allow Nagios to send Growl Notifications over the network.


 notify-growl options

=head1 OPTIONS
=over 4

=item B<-h|--help>

 Print help message and exit.

=item B<-H <hostaddress>>
 Hostaddress of the destination accepting Growl Notifications over the network. 
(Default: localhost)

=item B<-a|--application>

 Application name used to register to Growl. (Default: Nagios)

=item B<-t|--title>
 Title of the Growl notification. (Default: Alert)

=item B<-m|--message>
 Message of the Growl notification.

=item B<-P|--priority>

 Priority of the Growl notification. (Default: 2)

=item B<-s|--sticky>
 Sticky Growl notification. (Default: no)

=item B<-p|--password>

 Password to connect to the destination accepting Growl Notifications over the 



 define command {
  command_name  notify-host-by-growl
  command_line  $USER1$/notify-growl -H localhost -p password -a Nagios -t 

 define command {
  command_name  notify-service-by-growl
  command_line  $USER1$/notify-growl -H localhost -p password -a Nagios -t 


Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
Nagios-users mailing list
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue. 
::: Messages without supporting info will risk being sent to /dev/null

Reply via email to