Script to Check IP Address Attributes

From Observer GigaFlow Support | VIAVI Solutions Inc.
Revision as of 11:59, 23 November 2018 by Niall (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

var utils = Java.type('ros.CROSUtils');
updateAttribute("","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+" multiple 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));
           log.warn("Updating "+ipaddress+" single attribute from :"+atrribs.get(0) +" to "+newattribute);
 	log.warn("No "+ipaddress+" attributes for category:"+category+" ,adding");
   log.warn("No such IP address known"+ipaddress);