#!/usr/bin/perl
# Copyright 2008 by Ingo Lantschner (ingo@boxbe.com)
# 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 3 of the License, or
# (at your option) any later version. See <http://www.gnu.org/licenses/>.


use lib "./modules";  
use NaServer;
use NaElement;
use strict;
use warnings;

# VERSION = "0.1 ALPHA_NagKonf" -  funktionales Rohgerüst - noch kein Nagios-Plugin

my $filer = "sim3";
my $major_version = 1;
my $minor_version = 3;
my $user = "nagios";
my $pass = "nagios88";
my $debug ="1"; # 0 bis 2
my $out; # nimmt später die XML-Daten der ONTAP-API auf

# Schritt 1: Servercontext erzeugen
my $s = NaServer->new ($filer, $major_version, $minor_version);

# Schritt 2: Sessionparameter setzen
check_out($s->set_transport_type("HTTP"));
check_out($s->set_style("LOGIN_PASSWORD"));
check_out($s->set_admin_user($user, $pass));

# Schritt 3: Sende Komando an die Core API des Filers
$out = $s->invoke( "volume-list-info");
print Dumper($out) if $debug > 2;
if ($out->results_status() eq "failed"){
	my $r = $out->results_reason();
    print "ERROR invoking volume: $r\n";
	exit 3;
}

my $volume_info = $out->child_get("volumes");
my @result = $volume_info->children_get();

foreach my $vol (@result){
	my $vol_name = $vol->child_get_string("name");
	print  "Volume name: $vol_name \n" if $debug > 0;
	my $size_total = $vol->child_get_int("size-total");
	print  "Total Size: $size_total bytes \n" if $debug > 0;
	my $size_used = $vol->child_get_int("size-used");
	print  "Used Size: $size_used bytes \n" if $debug > 0;
	my $belegtPrzt = $vol->child_get_int("percentage-used");
	print  "Used Size: $belegtPrzt % \n------------------------------\n" if $debug > 0;
}

# Subroutine um Fehler bei Verwendung der NaServer Class Methoden abzufangen
sub check_out {
	my $out = $_[0];
	if (ref ($out) eq "NaElement") {
		if ($out->results_errno != 0) {
			my $r = $out->results_reason();
			print "ERROR: $r";
			exit 3;
		}
	}
}