( $host, $type ) = ( $args{"host"}, $args{"cmd"} );
my $alias = $args{"alias"};
$provider = "snmp";

$args{"_eval"} = "storage";
do "_evaluator";

%snmp_types = ( "novell", ":novell:net:storage:cpu:nwusers:ping:",
		"linux", ":linux:net:ping:storage:", 
		"nt", ":nt:net:ping:", 
		"caty", ":caty:hub:ping:", 
		"hub", ":hub:ping:", 
		"cds", ":cds:net:ping:",
		"notes", ":net:ping:",
		"asx", ":asxcpu:");
my $community = $args{"community"}?$args{"community"}:"public";
$type = $snmp_types{$type};
if( $args{"type"} ) {
    $type = $args{"type"};
    $type =~ s/,/:/g;
    $type = ":".$type.":";
}

unless( $snmp = $memory{"snmp_$args{host}_$community_$args{frequency}"} ) {
    &uxmon::load_module( "snmp" );
    &uxmon::checker(
	$memory{"snmp_$args{host}_$community_$args{frequency}"} = $snmp = Monitor::snmp->new( $host, $community )
    );
    $snmp->sched_frequency( $args{"frequency"} );
}
if( $type =~ /:ping:/ ) {
    $snmp->poll_fail( "$alias.conn" );
}
if( $type =~ /:(net|hub):/ ) {
    my( $iface, $speed );
    if ( $type =~ /:hub:/ ) {
	$snmp->add_walk_check( "ifInErrors", undef, "$alias.net", "IE", "PERSEC", undef, undef, 2, 6 );
	$snmp->add_walk_check( "ifOutErrors", undef, "$alias.net", "OE", "PERSEC", undef, undef, 2, 6 );
	$snmp->add_walk( "ifInErrors" );
	$snmp->add_walk( "ifOutErrors" );
    } else {
	$snmp->add_walk_check( "ifOperStatus", undef, "$alias.net", "Up", undef, 1 );
	$snmp->add_walk_check( "ifInErrors", undef, "$alias.net", "InErrors", "PERSEC", undef, undef, 2, 6 );
	$snmp->add_walk_check( "ifOutErrors", undef, "$alias.net", "OutErrors", "PERSEC", undef, undef, 2, 6 );
	$snmp->add_walk( "ifOperStatus" );
	$snmp->add_walk( "ifInErrors" );
	$snmp->add_walk( "ifOutErrors" );
    }
}
if( $type =~ /:storage:/ ) {
    my( @ids ) = $snmp->walk( "hrStorageIndex" );
    my( $sdescr, $ssize, $stype, $sunit );

    foreach $id (@ids) {
	$id =~ s/.*://;
	$sdescr = (($snmp->get( "hrStorageDescr.$id" ))[0]);
	$ssize = (($snmp->get( "hrStorageSize.$id" ))[0]);
	$stype = (($snmp->get( "hrStorageType.$id" ) )[0]);
	$sunit = (($snmp->get( "hrStorageAllocationUnits.$id" ) )[0]);
	print "  id $id, $stype, $sdescr, $ssize\n" if( $BigSister::common::dl>7 );
	my $types = "none";
	my %types;
	if( $type =~ /:nt:/ ) {
	    # Logical drives + Main Memory + Page File Memory
	    $types = "2|3|4";
	    %types = ( "2" => "physmem", "3" => "pagemem", "4" => "disk"); 
	}
	if( $type =~ /:novell:/ ) {
	    # Logical Volumes + Alloc Memory Pools
	    $types = "1|3";
	    %types = ( "1" => "disk", "3" => "pagemem" ); 
	}
	if( $type =~ /:linux:/ ) {
	    # Partitions + Main Memory + swap
	    $types = "2|3|4";
	    %types = ( "4" => "disk",
		       "2" => "physmem",
		       "3" => "pagemem" ); 
	}
	print "  storage oids: $types\n" if( $BigSister::common::dl>7 );
	if ( $ssize && $stype =~ /\.($types)$/ ) {
	    print "  $sdescr matched $1, id $id\n" if( $BigSister::common::dl>7 );
	    $storage_type = $types{$1};
	    $storage_descr = $sdescr;
	    $storage_id = $id;
	    $args{"_check"} = 0;
	    do "_storage";
	    if( $args{"_check"} ) {
		$snmp->add_check( "hrStorageUsed.$id" );
		$snmp->add_check( "hrStorageSize.$id" );
		$snmp->add_check( "hrStorageDescr.$id" );
		$snmp->add_check( "hrStorageAllocationUnits.$id" );
	    }
	}
    }
}
if( $type =~ /:cpu:/ ) {
    $snmp->add_walk_check( "hrProcessorLoad", undef, "$alias.cpu", "%cpu", undef, undef, undef, 80, undef );
    $snmp->add_walk( "hrProcessorLoad" );
}
if( $type =~ /:asxcpu:/ ) {
    $snmp->add_walk_check( "ASXProcUtil", undef, "$alias.cpu", "%cpu", undef, undef, undef,   75, 90 );
    $snmp->add_walk( "ASXProcUtil" );
}
if( $type =~ /:nwusers:/ ) {
    my( @uinfo );

    @uinfo = $snmp->get( "nwMaxLogins.0" );
    if( @uinfo ) {
	$snmp->add_check( "nwLoginCount.0", "$alias.cpu", "logged in users(max: ".$uinfo[0].")", undef,undef, undef, $uinfo[0]-10, $uinfo[0]-2 );
    }
}
if( $args{"procs"} ) {
    $snmp->add_walk( "hrSWRunName" );
    $args{"domain"} = $args{"host"}.":snmp";
    do "procs";
}

1;
