my ($snmp, $softkey, $evaluator);
my $community = $args{"community"}?$args{"community"}:"public";
my $frequency = $args{"frequency"}?$args{"frequency"}:10;
my $sw_version = $args{"expected"};
($sw_version = ".*ForeThought_6\.0\.1.*\(1\.49545\)") unless( $sw_version );

unless( $snmp = $memory{"snmp_$args{host}_$community_$frequency"} ) {
    &uxmon::load_module( "snmp" );
    &uxmon::checker(
	$memory{"snmp_$args{host}_$community_$frequency"} = $snmp = Monitor::snmp->new( $args{host}, $community )
    );
    $snmp->sched_frequency( $frequency );
}

do "_evaluator";
$evaluator = $args{_evaluator};

unless (defined $evaluator) {
    #Drop out gracefully?  Maybe later.
    print "_evaluator returned null object";
}

if ($args{"type"} eq 'asx') {
    # FORE ASX1000,ASX200 ATM Switches
    $snmp->add_check( "ASXSoftware.0", $args{"alias"}.".software" );
    $evaluator->add_check("software", sub {
	my ( $vars ) = @_;
	my ( $color, $probs, $text );

	my $software = $vars->{"snmp.ASXSoftware.0"};
	$color = 3;
	if ($software=~/$sw_version/) {
	    $probs = "&green Software version is up to date as of 12/4/99";
	    $text = $software;
	} elsif (defined $software) {
	    $color = 1;
	    $probs = "&yellow Software version is out of date!";
	    $text = $software;
	} else {
	    $color = 0;
	    $probs = "&red Could not query software version!";
	    $text = ""; # $SNMP_Session::errmsg;
	}
	return ($color, "\n$probs\n\n$text");
    } );
} elsif ($args{"type"} eq 'asn9000') {
    # FORE ASN9000, PowerHub support
    $snmp->add_check( "ASNSoftware.0", $args{"alias"}.".software" );
    $evaluator->add_check("software", sub {
	my ( $vars ) = @_;
	my ( $color, $probs, $text );

	my $software = $vars->{"snmp.ASNSoftware.0"};
	$color = 3;
	#if ($software=~/$sw_version/) {
	if (defined $software) {
	    $probs = "&green We don't monitor this version of code";
	    $text = $software;
	#} elsif (defined $software) {
	#    $color = 1;
	#    $probs = "&yellow Software version is out of date!";
	#    $text = $software;
	} else {
	    $color = 0;
	    $probs = "&red Could not query software version!";
	    $text = ""; # $SNMP_Session::errmsg;
	}
	return ($color, "\n$probs\n\n$text");
    } );
} elsif ($args{"type"} eq 'es2810') {
    # FORE ES2810 Ethernet switch
    $snmp->add_check( "sysDescr.0", $args{"alias"}.".software" );
    #$snmp->add_check( "ES2810ModSoftware", $args{"alias"}.".software" );
    $evaluator->add_check("software", sub {
	my ( $vars ) = @_;
	my ( $color, $probs, $text );

	my $software = $vars->{"snmp.sysDescr.0"};
	my $myver = $snmp->get( "ES2810ModSoftware" );
	$color = 3;
	if ($software=~/.*Version 2.51e/) {
	    $probs = "&green Core software version is up to date as of 12/4/99";
	    $text = $software;
	} elsif (defined $software) {
	    $color = 1;
	    $probs = "&yellow Core software version is out of date!";
	    $text = $software;
	} else {
	    $color = 0;
	    $probs = "&red Could not query core software version!";
	    $text = ""; # $SNMP_Session::errmsg;
	}
	if ($modver=~/.*5.2.3/) {
	    $probs .= "\n&green Module software version is up to date as of 12/4/99";
	    $text .= "\nModule Version: $modver";
	} elsif (defined $modver) {
	    $color = ($color<1)?$color:1;
	    $probs .= "\n&yellow Module software version is out of date!";
	    $text .= "\nModule Version: $modver";
	}
	return ($color, "\n$probs\n\n$text");
    } );
} else {
    # Generic Fallback
    $snmp->add_check( "sysDescr.0", $args{"alias"}.".software" );
    $evaluator->add_check("software", sub {
	my ( $vars ) = @_;
	my ( $color, $probs, $text );

	my $software = $vars->{"snmp.sysDescr.0"};
	$color = 3;
	#if ($software=~/.*ForeThought_6\.0\.1.*\(1\.49545\)/) {
	if( (defined $software) && ($software=~/$sw_version/)) {
	    $probs = "&green Software version OK";
	    $text = $software;
	} elsif (defined $software) {
	    $color = 1;
	    $probs = "&yellow wrong Software version";
	    $text = $software;
	} else {
	    $color = 1;
	    $probs = "&yellow Could not query software version!";
	    $text = ""; # $SNMP_Session::errmsg;
	}
	return ($color, "\n$probs\n\n$text");
    } );
}

1;
