WCM - Das österreichische Computer Magazin Forenübersicht
 

Zurück   WCM Forum > Rat & Tat > Programmierung

Programmierung Rat & Tat für Programmierer

Microsoft KARRIERECAMPUS

 
 
Themen-Optionen Ansicht
Alt 09.03.2004, 09:19   #1
spunz
Super-Moderator
 
Registriert seit: 22.03.2000
Beiträge: 9.666


spunz eine Nachricht über ICQ schicken
Standard kleines perl script umbauen

ich hab hier ein perl script vom nagios projekt. damit wird der freie speicher eines shares überwacht.

die ausgabe schaut in etwa so aus:

Code:
Domain=[Work] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]
Disk ok - 2.92G (73%) free on \\192.168.0.1\hdiskc
nun möchte ich schöne grafiken über den verbrauch des freien speichers diverser shares in cacti einrichten, dazu benötige ich aber einen reinen zahlenwert. es muß nicht unbedingt dieses perlscript sein, eine lösung als shellscript/php würde es auch tun.



hier das perl script, ich habe es auf 2 threads aufteilen müssen:

Code:
#! /usr/bin/perl 
#-wT
#
#
# check_disk.pl <host> <share> <user> <pass> [warn] [critical] [port]
#
# NetSaint host script to get the disk usage from a SMB share
#
# Changes and Modifications
# =========================
# 7-Aug-1999 - Michael Anthon
#  Created from check_disk.pl script provided with netsaint_statd (basically
#  cause I was too lazy (or is that smart?) to write it from scratch)
# 8-Aug-1999 - Michael Anthon
#  Modified [warn] and [critical] parameters to accept format of nnn[M|G] to
#  allow setting of limits in MBytes or GBytes.  Percentage settings for large
#  drives is a pain in the butt

BEGIN {
	if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
		$runtimedir = $1;
		$PROGNAME = $2;
	}
}

require 5.004;
use POSIX;
use strict;
use Getopt::Long;
use vars qw($opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $verbose);
use vars qw($PROGNAME);
use lib $main::runtimedir;
use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);

sub print_help ();
sub print_usage ();
sub help ();
sub version ();

delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

Getopt::Long::Configure('bundling', 'no_ignore_case');
GetOptions
	("V|version"     => \&version,
	 "h|help"        => \&help,
   "v|verbose"     => \$verbose,
	 "w|warning=s"   => \$opt_w,
	 "c|critical=s"  => \$opt_c,
	 "p|password=s"  => \$opt_p,
	 "u|username=s"  => \$opt_u,
	 "s|share=s"     => \$opt_s,
	 "W|workgroup=s" => \$opt_W,
	 "H|hostname=s"  => \$opt_H);

my $smbclient="smbclient";
my $smbclientoptions="";

($opt_H) || ($opt_H = shift) || usage("Host name not specified\n");
my $host = $1 if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]*(\.[a-zA-Z][-a-zA-Z0-9]*)*)$/);
($host) || usage("Invalid host: $opt_H\n");

($opt_s) || ($opt_s = shift) || usage("Share volume not specified\n");
my $share = $1 if ($opt_s =~ /([-_.A-Za-z0-9]+)/);
($share) || usage("Invalid share: $opt_s\n");

($opt_u) || ($opt_u = shift) || ($opt_u = "guest");
my $user = $1 if ($opt_u =~ /([-_.A-Za-z0-9]+)/);
($user) || usage("Invalid user: $opt_u\n");

($opt_p) || ($opt_p = shift) || ($opt_p = "guest");
my $pass = $1 if ($opt_p =~ /(.*)/);

($opt_w) || ($opt_w = shift) || ($opt_w = 85);
my $warn = $1 if ($opt_w =~ /([0-9]{1,2}\%?|100\%?|[0-9]+[kmKM])+/);
($warn) || usage("Invalid warning threshold: $opt_w\n");

($opt_c) || ($opt_c = shift) || ($opt_c = 95);
my $crit = $1 if ($opt_c =~ /([0-9]{1,2}\%?|100\%?|[0-9]+[kmKM])/);
($crit) || usage("Invalid critical threshold: $opt_c\n");

my $workgroup = $1 if (defined($opt_W) && $opt_W =~ /(.*)/);

my $state = "OK";
my $answer = undef;
my $res = undef;
my @lines = undef;

# Just in case of problems, let's not hang NetSaint
$SIG{'ALRM'} = sub { 
	print "No Answer from Client\n";
	exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);
spunz ist offline   Mit Zitat antworten
 


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 06:11 Uhr.


Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Forum SEO by Zoints
© 2009 FSL Verlag