#!/usr/bin/perl # Nagios plugin for monitoring dropbox # Written by Adrian Bridgett (c) Bitcube Ltd. 2010 # Released under GPL v3 license # For opsview use lib '/usr/local/nagios/perl/lib', '/usr/local/nagios/lib'; use warnings; use strict; use Nagios::Plugin; my $VERSION = "0.01"; my $program = "/usr/bin/dropbox"; my $np = Nagios::Plugin->new( usage => "Usage: %s [-u user] [-f filename", version => $VERSION, blurb => "Checks dropbox status", ); $np->add_arg( spec => "user|u=s", help => qq{-u, --user=STRING User to check dropbox status of}, default => "", ); $np->add_arg( spec => "file|f=s", help => qq{-f, --file=STRING File to check sync status of}, default => "", ); $np->getopts; if ($np->opts->user) { $ENV{"HOME"}="/home/" . $np->opts->user; } open DROPBOX, "$program status|" or $np->nagios_exit(UNKNOWN, "Unable to run $program"); my $status = ; chomp $status; close DROPBOX; if ($status ne "Idle") { $np->nagios_exit(CRITICAL, "Dropbox is $status"); } my $file = $np->opts->file; if ($file) { my $filepath = $file; if ($filepath !~ m!^/!) { $filepath = "~" . $np->opts->user . "/$file"; } open DROPBOX, "$program filestatus $filepath|" or $np->nagios_exit(UNKNOWN, "Unable to run $program"); my $filestatus = ; chomp $filestatus; $filestatus =~ s/[^:]*: //; close DROPBOX; if ($filestatus eq "up to date") { $np->nagios_exit(OK, "Dropbox is $status. $file is $filestatus."); } else { $np->nagios_exit(WARNING, "Dropbox is $status. $file is $filestatus."); } } $np->nagios_exit(OK, "Dropbox is $status");