SCRIPT: Detecting devices that have changed vendor/device type

THIS IS A CUSTOMER GENERATED SCRIPT AND COMES WITH NO WARRANTY OR SUPPORT. PROCEED AT YOUR OWN RISK.
 
March 2022
 
My team is swapping out a ton of devices from vendor x to vendor y. They are however keeping the IP address and device name the same. Because of this I am finding devices from vendor y with entries in the database from vendor x. This lead me to write the two following site scripts.
 
I am not a perl veteran....and of course your mileage may vary...feedback welcome.
 
 
#####
# Script to look at existing devices and see if they have attributes with names starting from different vendors.
# You may need to update with your vendor names
# This script I pretty expensive as it looks at all devices and all attributes. Should only need to be run once before the other script can kick in
#####
 
sub custom_multivendor_detection {
my @body;
my $dcnt =0;
 
for my $devname (adb_result ("mlist device *")) {
my @checks = ('^HP-', '^JUNIPER-', '^ARUBA', '^CISCO', '^FOUNDRY', '^BROCADE');
my $vcnt =0;
my $ip = adb_result (sprintf("get %s sys ip4addr", $devname)) || "";
 
while (@checks) {
my $check = shift @checks;
 
my $result = adb_result (sprintf("mget * %s * /%s/", $devname, $check)) || "none";
 
if ($result ne "none") {$vcnt++;}
 
if ($vcnt > 1) {
printf ("Multivendor detection: %s\n", $devname);
push @body, sprintf ("%s : %s",$devname, $ip);
$dcnt++;
last;
}
}
}
 
if (@body) {
mail ({
to => "you\@yourcompany.com",
subject => "Multivendor detection",
body => \@body,
});
}
}
 
 
#####
# Script to copy current sysObjectID into a backup field and alert via email if it changes. This should only be run once you are sure that all devices are 'clean'
#####
 
sub config_sysObjectID_change {
my @body;
for my $line (adb_result ("mget text * sys SNMPv2-MIB.sysObjectID")) {
my ($devname, undef, undef, undef, $sysObjectID) = split (" ", $line, 5);
my $known = adb_result (sprintf("get %s sys KnownsysObjectID ", $devname)) || "";
 
if ($known eq "") {
adb_send (sprintf ("add text %s sys KnownsysObjectID = %s", $devname, $sysObjectID));
}
elsif ($known ne $sysObjectID) {
push @body, sprintf ("%s sysObjectID changed from: %s to: %s", $devname, $known, $sysObjectID);
}
 
}
mail ({
to => "you\@yourcompany.com",
subject => "sysObjectID change detection",
body => \@body,
});
adb_flush ();
}

Was this article helpful?

/

Comments

0 comments

Please sign in to leave a comment.