Changeset 210 for trunk/klask


Ignore:
Timestamp:
Feb 16, 2017, 9:49:10 PM (7 years ago)
Author:
g7moreau
Message:
  • Update method cmd_enable and cmd_disable
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r209 r210  
    19701970
    19711971sub cmd_enable {
    1972    my $switch = shift;
    1973    my $port   = shift;
     1972   @ARGV = @_;
     1973
     1974   my $verbose;
     1975
     1976   GetOptions(
     1977      'verbose|v' => \$verbose,
     1978      );
     1979
     1980   my $switch_name = shift @ARGV || q{};
     1981   my $port        = shift @ARGV || q{};
     1982
     1983   if ($switch_name eq q{} or $port eq q{}) {
     1984      die "Usage: klask disable SWITCH_NAME PORT\n";
     1985      }
     1986
     1987   if (not defined $SWITCH_DB{$switch_name}) {
     1988      die "Switch $switch_name must be defined in klask configuration file\n";
     1989      }
     1990
     1991   my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port;
     1992   print "Info: switch $switch_name port $port SNMP OID $search_portstatus\n" if $verbose;
     1993
     1994   my $sw = $SWITCH_DB{$switch_name};
     1995   my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} );
     1996   print "$error \n" if $error;
     1997
     1998   my $result = $session->set_request(
     1999      -varbindlist => [$search_portstatus, INTEGER, 1],
     2000      );
     2001
     2002   $session->close;
    19742003
    19752004   #snmpset -v 1 -c community X.X.X.X 1.3.6.1.2.1.2.2.1.7.NoPort = 1 (up)
    19762005   #snmpset -v 1 -c community X.X.X.X 1.3.6.1.2.1.2.2.1.7.NoPort = 2 (down)
    1977    system "snmpset -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port = 1";
     2006   #system "snmpset -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port = 1";
    19782007   return;
    19792008   }
    19802009
    19812010sub cmd_disable {
    1982    my $switch = shift;
    1983    my $port   = shift;
    1984 
    1985    system "snmpset -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port = 2";
     2011   @ARGV = @_;
     2012
     2013   my $verbose;
     2014
     2015   GetOptions(
     2016      'verbose|v' => \$verbose,
     2017      );
     2018
     2019   my $switch_name = shift @ARGV || q{};
     2020   my $port        = shift @ARGV || q{};
     2021
     2022   if ($switch_name eq q{} or $port eq q{}) {
     2023      die "Usage: klask disable SWITCH_NAME PORT\n";
     2024      }
     2025
     2026   if (not defined $SWITCH_DB{$switch_name}) {
     2027      die "Switch $switch_name must be defined in klask configuration file\n";
     2028      }
     2029
     2030   my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port;
     2031   print "Info: switch $switch_name port $port SNMP OID $search_portstatus\n" if $verbose;
     2032
     2033   my $sw = $SWITCH_DB{$switch_name};
     2034   my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} );
     2035   print "$error \n" if $error;
     2036
     2037   my $result = $session->set_request(
     2038      -varbindlist => [$search_portstatus, INTEGER, 2],
     2039      );
     2040
     2041   $session->close;
     2042
     2043   #system "snmpset -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port = 2";
    19862044   return;
    19872045   }
     
    24862544
    24872545 klask enable  switch port
    2488  klask disable swith port
     2546 klask disable switch port
    24892547 klask status  swith port
    24902548
     
    25262584This command activate a port on a switch by SNMP.
    25272585So you need to give the switch and the port number on the command line.
     2586Actually, port number must be a number and not the name alias...
    25282587
    25292588
     
    25322591This command deactivate a port on a switch by SNMP.
    25332592So you need to give the switch and the port number on the command line.
     2593Actually, port number must be a number and not the name alias...
    25342594
    25352595
     
    25382598This command return the status of a port number on a switch by SNMP.
    25392599So you need to give the switch name and the port number on the command line.
     2600Actually, port number must be a number and not the name alias...
    25402601
    25412602
Note: See TracChangeset for help on using the changeset viewer.