Difference between revisions of "Script to Check IP Address Attributes"

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search
(Created page with "Checking whether an ip address has attributes in a category var utils = Java.type('ros.CROSUtils'); var address="172.21.21.21" if (actions.allIPs.containsKey(utils.inet_ato...")
 
Line 1: Line 1:
Checking whether an ip address has attributes in a category
+
Checking whether an ip address has attributes in a category, adding or updating
 
  var utils = Java.type('ros.CROSUtils');
 
  var utils = Java.type('ros.CROSUtils');
  var address="172.21.21.21"
+
  updateAttribute("172.21.21.21","Function2","Kevins PC2");
  if (actions.allIPs.containsKey(utils.inet_atob(address))){
+
  function updateAttribute(ipaddress,category,newattribute){
var ip = actions.allIPs.get(utils.inet_atob(address))
+
if (actions.allIPs.containsKey(utils.inet_atob(ipaddress))){
log.warn(ip);
+
var ip = actions.allIPs.get(utils.inet_atob(ipaddress))
  var atrribs = ip.getAttributes("Function")
+
var categoryid = ip.getCategory(category);
  if (atrribs.length()>0){
+
  var atrribs = ip.getAttributes(categoryid)
  log.warn("Already have attribute:"+atrribs);
+
  if (atrribs.length()>1){
  }else{
+
  log.warn("Already have "+ipaddress+" multuple attributes:"+atrribs);
  log.warn("No attributes");
+
  }else if (atrribs.length()==1){
  }
+
  log.warn("Already have "+ipaddress+" single attribute:"+atrribs);
 +
          if (atrribs.get(0)===newattribute){
 +
            log.warn("Already have "+ipaddress+" same single attribute:"+atrribs.get(0));
 +
          }else{
 +
            log.warn("Updating "+ipaddress+" single attribute from :"+atrribs.get(0) +" to "+newattribute);
 +
          ip.removeAttrib(categoryid,atrribs.get(0));
 +
            ip.addAttrib(categoryid,newattribute);
 +
          }
 +
         
 +
}else{
 +
  log.warn("No "+ipaddress+" attributes for category:"+category+" ,adding");
 +
            ip.addAttrib(categoryid,newattribute);
 +
  }
 +
  }else{
 +
    log.warn("No such IP address known"+ipaddress);
 +
    }
 
  }
 
  }

Revision as of 07:54, 18 July 2018

Checking whether an ip address has attributes in a category, adding or updating

var utils = Java.type('ros.CROSUtils');
updateAttribute("172.21.21.21","Function2","Kevins PC2");
function updateAttribute(ipaddress,category,newattribute){

if (actions.allIPs.containsKey(utils.inet_atob(ipaddress))){ var ip = actions.allIPs.get(utils.inet_atob(ipaddress)) var categoryid = ip.getCategory(category);

 		var atrribs = ip.getAttributes(categoryid)
 		if (atrribs.length()>1){
 			log.warn("Already have "+ipaddress+" multuple attributes:"+atrribs);
 		}else if (atrribs.length()==1){
 			log.warn("Already have "+ipaddress+" single attribute:"+atrribs);
         if (atrribs.get(0)===newattribute){
           log.warn("Already have "+ipaddress+" same single attribute:"+atrribs.get(0));
         }else{
           log.warn("Updating "+ipaddress+" single attribute from :"+atrribs.get(0) +" to "+newattribute);
         	ip.removeAttrib(categoryid,atrribs.get(0));
           ip.addAttrib(categoryid,newattribute);
         }
         

}else{

 			log.warn("No "+ipaddress+" attributes for category:"+category+" ,adding");
           ip.addAttrib(categoryid,newattribute);
 		}
 	}else{
   log.warn("No such IP address known"+ipaddress);
   }
}