Sunday, January 27, 2008

Using Google Calendar to Monitor Software, part 3

I use Google Calendar to monitor automatic software execution in cron jobs. Here's the code.


#!/usr/bin/perl -w
# $Id: cal_event 5853 2007-04-02 16:46:01Z jhaemer $

use strict;

# get proprietary information from the accompanying file
# ""

my $app_dir = `dirname $0`;
chomp $app_dir;
push @INC, $app_dir;
require cal_event_proprietary; # defines %url, username, passwords
our %url; # the calendar_name => url hash

# get calendar and event from command line
@ARGV > 1 || die "usage: $0 calendar_name description\n";
my $calname = shift;
my $url = $url{$calname} || die "$calname: no such calendar\n";
my $title = "@ARGV";

# login
our ( $login, $passwd );
use Net::Google::Calendar;
my $cal = Net::Google::Calendar->new( url => $url );
$cal->login( $login, $passwd );

# create entry
my $entry = Net::Google::Calendar::Entry->new();
$entry->when( DateTime->now,
DateTime->now() + DateTime::Duration->new( minutes => 1 ) );

my $tmp = $cal->add_entry($entry);
die "Couldn't add event: $@\n" unless defined $tmp;

# $Id: cal_event 5853 2007-04-02 16:46:01Z jhaemer $


=head1 NAME

cal_event - announce an event in a Google calendar


cal_event calendar_name description


Makes an entry in the named calendar.


This program makes it easy to track status of cron jobs from a simple, calendar
interface, just by calling the program from the cron job.

if [ $? -eq 0 ]
cal_event ${0##*/} SUCCEEDED
cal_event ${0##*/} FAILED

=head1 BUGS and CAVEATS


=item *

Expects username, password, and calendar info in F.
See F for details.

=item *

All calendars need to be in the same account.


=head1 FILES

=head1 SEE ALSO


=head1 AUTHOR

Jeffrey S. Haemer

No comments: