Tuesday, May 21st 2013, 10:03pm UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to Monitoring-Portal.
Although this is a german monitoring forum, please don't hesitate to post in English. Nearly everybody here understands you and will answer in English as well.
If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form to register here or read more information about the registration process. If you are already registered, please login here.

shredman

Beginner

Posts: 15

Number of monitoring servers: 1

Nagios Version: 3.06

Distributed monitoring: Nein

Redundant monitoring: Nein

Number of hosts: 60

Number of services: 185

OS: Debian 5.0 Lenny

Plugin Version: 1.4.15

1

Thursday, July 21st 2011, 8:23am

Ausgabe "check_file_age.pl" in Minuten ?

Hi,

kann mir mal jemand auf die Sprünge helfen. Kenn mich leider nicht mit Perl aus und möchte, dass das Script check_file_age.pl das Dateialter nicht in Sekunden sondern in Minuten ausgibt. Ist bestimmt nur eine kleine Anpassung an den rot markierten Stellen oder liege ich falsch? Denke aber das es nicht reicht den Inhalt von $age einfach durch 60 zu teilen. Man bekommt ja dadurch einen Nachkommwert raus? Für die Cracks von Euch bestimmt Pipifax.. :)


#! /usr/bin/perl -w
# $Id: check_file_age.pl 1750 2007-07-07 11:54:29Z psychotrahe $

# check_file_age.pl Copyright (C) 2003 Steven Grimm <koreth-nagios@midwinter.com>
#
# Checks a file's size and modification time to make sure it's not empty
# and that it's sufficiently recent.
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# you should have received a copy of the GNU General Public License
# along with this program (or with Nagios); if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA

use strict;
use English;
use Getopt::Long;
use File::stat;
use vars qw($PROGNAME);
use lib "/usr/lib/nagios/plugins";
use utils qw (%ERRORS &print_revision &support);

sub print_help ();
sub print_usage ();

my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V);
my ($result, $message, $age, $size, $st);

$PROGNAME="check_file_age";

$opt_w = 240;
$opt_c = 600;
$opt_W = 0;
$opt_C = 0;
$opt_f = "";

Getopt::Long::Configure('bundling');
GetOptions(
"V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
"f=s" => \$opt_f, "file" => \$opt_f,
"w=f" => \$opt_w, "warning-age=f" => \$opt_w,
"W=f" => \$opt_W, "warning-size=f" => \$opt_W,
"c=f" => \$opt_c, "critical-age=f" => \$opt_c,
"C=f" => \$opt_C, "critical-size=f" => \$opt_C);

if ($opt_V) {
print_revision($PROGNAME, '$Revision: 1750 $');
exit $ERRORS{'OK'};
}

if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}

$opt_f = shift unless ($opt_f);

if (! $opt_f) {
print "FILE_AGE UNKNOWN: No file specified\n";
exit $ERRORS{'UNKNOWN'};
}

# Check that file exists (can be directory or link)
unless (-e $opt_f) {
print "FILE_AGE CRITICAL: File not found - $opt_f\n";
exit $ERRORS{'CRITICAL'};
}

$st = File::stat::stat($opt_f);
$age = time - $st->mtime;
$size = $st->size;


$result = 'OK';

if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) {
$result = 'CRITICAL';
}
elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) {
$result = 'WARNING';
}

print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n";
exit $ERRORS{$result};

sub print_usage () {
print "Usage:\n";
print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] -f <file>\n";
print " $PROGNAME [-h | --help]\n";
print " $PROGNAME [-V | --version]\n";
}

sub print_help () {
print_revision($PROGNAME, '$Revision: 1750 $');
print "Copyright (c) 2003 Steven Grimm\n\n";
print_usage();
print "\n";
print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n";
print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n";
print "\n";
support();
}



Danke im voraus.

Gruß,
Frank

striep

Professional

Posts: 597

Birthday: Jul 20th 1962 (50)

Gender: male

Location: Buxtehude, ja, gibt es wirklich ;-)

Number of monitoring servers: 4

Hobbies: Paracord, RaspberryPi

Nagios Version: --

Icinga Version: 1.8.4, omd 0.55-20120802, OMD 0.56

Distributed monitoring: Ja

Redundant monitoring: Ja

Number of hosts: 561

Number of services: 1921

OS: ubuntu 10.04, Solaris, Windows

Plugin Version: 1.4.x

IDO-Version: 1.8.4 but not live

Other Addons: pnp 0.6.15/18, NSClient++ 0.3.8, SEC, NSCA

2

Saturday, July 23rd 2011, 4:58pm

Hi,

aus

$st = File::stat::stat($opt_f);
$age = time - $st->mtime;
$size = $st->size;

wird

$st = File::stat::stat($opt_f);
$age = time - $st->mtime;
$age = $age/60;
$size = $st->size;


und aus

print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n";

wird

print "FILE_AGE $result: $opt_f is $age minutes old and $size bytes\n";


Gruß
Stefan
~~ Never touch a running system ~~
~~ Never run a touchy system ~~

anselm

Beginner

Posts: 4

Birthday: Sep 20th

Gender: male

Number of monitoring servers: 1 x Live, 1 x Dev

Nagios Version: 3.2.3

Distributed monitoring: Nein

Redundant monitoring: Nein

Number of hosts: 120 / 5

Number of services: 496 / 50

OS: Solaris 10 Sparc auf Sun Fire V215/V210 - Solaris 10 i386 - Windows Server 2003

Plugin Version: 1.4.15

Other Addons: pnp 0.6.11, check_multi, nsca

3

Monday, August 1st 2011, 7:20pm

Moin,
das Umwandeln in Minuten ist eine feine Sache......

Bei der Ausgabe werden aber x Stellen nach dem Komma angezeigt.

Hier noch eine Zeile zum runden.

$age = $age/60;
my $variable = sprintf "%.0f", $age;
$size = $st->size;

--> "%.0f" = Keine Nachkommastelle
--> "%.1f" = Eine Nachkommastelle

usw.

....

print "FILE_AGE $result: $opt_f is $variable minutes old and $size bytes\n";

MfG