A
A
Andrey Bondarchuk2014-11-27 11:06:05
Cisco
Andrey Bondarchuk, 2014-11-27 11:06:05

Bulk hardware configuration (again), replacing SNMP-server name -> hostname?

Hello!
I'll put aside the formalities like: "I just started working in the field of administration and ran into the problem of mass configuration of equipment ... With the development of scripts, I'm on" you ", but if you wish ... and blah blah blah" The
task is to replace the SNMP-server name to hostname.
I googled, found options from which to push off:
smart-bit.livejournal.com/9060.html
www.lissyara.su/articles/freebsd/coding/zyxel_conf...
And everything would be fine, but how to request a hostname from a piece of iron (i.e. . exactly what is written before the "#" sign)?
Please tell me how this can be implemented, or share a ready-made solution.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Bondarchuk, 2016-09-08
@sh1kima26

Already forgot about this issue. Meanwhile, I solved the problem as follows:
The script accesses the txt file, which contains the addresses and the necessary names in the format "255.255.255.255|hostname", separates the address from the text, puts them into separate variables, then goes to the address specified in the variable with the address and performs the required operations. In a name replacement operation, substitutes a variable with a hostname in the command text. Saves the settings and leaves the device. The cycle repeats until the end of the text file.

#while (<$IPadd>)
while (defined($Source = <TEMP>))
{
($IPadd, $Hostname) = (split/\|/ , $Source);
my ($command1)="$Hostname";
print "$Source $IPadd\n $Hostname";
$counter++;
         chomp ($_);
           $t->open($IPadd);
           $t->waitfor('/:$/i');
           $t->print($username);
           $t->waitfor('/:$/i');
           $t->print($passwd);
       $t->print ("$ena");
       $t->print ("$conf");
      $t->print("hostname $command1");
      $t->print("$command_exit");
        my @command= $t->cmd(Timeout => 60, String =>"$command_wrmem");
      @command= $t->cmd(Timeout => 60, String => 'y');
      $t->print("$command_exit");
      #$t->print("$command_exit");
      print "$counter",' ';
}
close TEMP;
print ('done on ',"$counter",' ');

Pauses at the end were set due to the fact that on some pieces of iron the configuration was not saved.
The method is not ideal, but at one time it helped to seriously speed up the work.

A
Alexander Karabanov, 2014-11-27
@karabanov

[email protected]: $ snmpwalk -v2c -c secretCommunity 172.32.5.254 SNMPv2-MIB::sysName.0
SNMPv2-MIB::sysName.0 = STRING: Shestaka_12_DGS
[email protected]: $

In the form of numbers, sysName.0 looks like 1.3.6.1.2.1.1.5

T
throughtheether, 2014-11-28
@throughtheether

Please tell me how it can be implemented
In my opinion, the easiest way to implement this is with expect/pexpect. You should (programmatically) log in to each device, get the hostname (from the greeting or configuration), form a new command (snmp-server name ) and execute it. There is a suspicion that it will be difficult to implement this using SNMP.
If you need further help, at least the device models and how to access them (ssh / telnet) specify.

A
Ars1s, 2014-11-28
@Ars1s

There is a wonderful product from the vendor of the same name - Cisco Prime Infrastructure, your task is solved in a couple of clicks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question