Difference between revisions of "SNMP Access Using Scripts"

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search
Line 1: Line 1:
 
Querying a number (uptime in this case) from an infrastructure device
 
Querying a number (uptime in this case) from an infrastructure device
  var ip="83.70.199.182"
+
  var ip="83.70.199.182" //Set Ip address
  var thisDevice = actions.getDevice(ip);
+
  var thisDevice = actions.getDevice(ip); //Get managed device
  if (thisDevice != null) {
+
  if (thisDevice != null) { //Check if it exists in the system
   var uptime = actions.querySNMPNumber(thisDevice, '.1.3.6.1.2.1.1.3.0', -1);
+
   var uptime = actions.querySNMPNumber(thisDevice, '.1.3.6.1.2.1.1.3.0', -1); //Query device for uptime and store
   log.warn('Uptime for device ' + ip+" "+thisDevice.getName()+" "+uptime);
+
   log.warn('Uptime for device ' + ip+" "+thisDevice.getName()+" "+uptime); //Write information to log
 
  }else{
 
  }else{
   log.warn("No such managed device "+ip);
+
   log.warn("No such managed device "+ip); //Alert that device isn't a known infrastructure device
 
  }
 
  }
  
 
Getting the SysOID of a device and determining if its a Cisco device
 
Getting the SysOID of a device and determining if its a Cisco device
  
  var ip="83.70.199.180"
+
  var ip="83.70.199.182" //Set Ip address
  var thisDevice = actions.getDevice(ip);
+
  var thisDevice = actions.getDevice(ip); //Get managed device
  if (thisDevice != null) {
+
  if (thisDevice != null) { //Check if it exists in the system
   log.warn('sysOID for device ' + ip+" "+thisDevice.getName()+" "+thisDevice.getSysOID());
+
   log.warn('sysOID for device ' + ip+" "+thisDevice.getName()+" "+thisDevice.getSysOID()); //Write details to log
   if (thisDevice.getSysOID().indexOf('1.3.6.1.4.1.9')==0){
+
   if (thisDevice.getSysOID().indexOf('1.3.6.1.4.1.9')==0){ //Look for Ciscos OID and see if it exists ==0
   log.warn("Is Cisco");
+
   log.warn("Is Cisco");//Write to log
 
   }
 
   }
 
  }else{
 
  }else{
   log.warn("No such managed device "+ip);
+
   log.warn("No such managed device "+ip); //Alert that device isn't a known infrastructure device
 
  }
 
  }

Revision as of 09:44, 23 January 2017

Querying a number (uptime in this case) from an infrastructure device

var ip="83.70.199.182" //Set Ip address
var thisDevice = actions.getDevice(ip); //Get managed device
if (thisDevice != null) { //Check if it exists in the system
 var uptime = actions.querySNMPNumber(thisDevice, '.1.3.6.1.2.1.1.3.0', -1); //Query device for uptime and store
 log.warn('Uptime for device ' + ip+" "+thisDevice.getName()+" "+uptime); //Write information to log
}else{
 log.warn("No such managed device "+ip); //Alert that device isn't a known infrastructure device
}

Getting the SysOID of a device and determining if its a Cisco device

var ip="83.70.199.182" //Set Ip address
var thisDevice = actions.getDevice(ip); //Get managed device
if (thisDevice != null) { //Check if it exists in the system
 log.warn('sysOID for device ' + ip+" "+thisDevice.getName()+" "+thisDevice.getSysOID()); //Write details to log
 if (thisDevice.getSysOID().indexOf('1.3.6.1.4.1.9')==0){ //Look for Ciscos OID and see if it exists ==0
  log.warn("Is Cisco");//Write to log
 }
}else{
 log.warn("No such managed device "+ip); //Alert that device isn't a known infrastructure device
}