Joe_Williams
Expert
6 years agoGroovy Script and Instancing
I am writing a Groovy DataSource for covering some items that aren't there by default for Nimble.
I am having issues getting the data to appear properly under the instances I would think it should.
Active Discovery is this and it works as expected.
import com.santaba.agent.groovyapi.expect.Expect; import com.santaba.agent.groovyapi.snmp.Snmp; import com.santaba.agent.groovyapi.http.*; import com.santaba.agent.groovyapi.jmx.*; import org.xbill.DNS.*; hostname = hostProps.get("system.hostname"); nimuser=hostProps.get("nim.user"); nimpass=hostProps.get("nim.pass"); cli = Expect.open(hostname, nimuser,nimpass) cli.send("ctrlr --list \n\r") cli.expect(/-----/) cli.expect("Nimble OS") commandOutput=cli.before() //We only want the output from after the first header row to end of the command (when the prompt is back) commandOutput.eachLine { if (!(it =~ /-----/) && !(it =~ /Name\s*State\s*Hostname /)) { //ignore table header if (it.startsWith("A") || it.startsWith("B")) { tokens = it.split(); //println it //print tokens[0]; //println "\r\n" controller = tokens[0] controllername = tokens[2] println controller+"##"+controllername } } } cli.send("exit \n\r") cli.expectClose()
I then have the below for the main part of the script. It is currently just a POC. I am not grabbing everything I want yet. When I test the script I get back what I want, but no matter what, the instances for the fans do not show up under the Controllers.
import com.santaba.agent.groovyapi.expect.Expect; import com.santaba.agent.groovyapi.snmp.Snmp; import com.santaba.agent.groovyapi.http.*; import com.santaba.agent.groovyapi.jmx.*; import org.xbill.DNS.*; hostname = hostProps.get("system.hostname"); nimuser=hostProps.get("nim.user"); nimpass=hostProps.get("nim.pass"); arraydesc = "##WILDALIAS##"; cli = Expect.open(hostname, nimuser,nimpass) cli.send("ctrlr --info ##WILDVALUE## \n\r") cli.expect("Name: ") cli.expect("Nimble OS") commandOutput=cli.before() commandOutput.eachLine // { instance_index, it -> { // println it; if (it.startsWith("\tpower-supply")) { nametokens = it.split(" at "); psname = nametokens[0]; psname = psname.trim(); psname = psname.replace("\t", ""); psdescr = nametokens[1]; psdescr = psdescr.split(":"); psdescr = psdescr[0]; tokens = it.split(": "); psstate = tokens[1]; psstate = psstate.trim(); psstate = psstate.replace("\t", ""); if (psstate == "ok") { psstate = "0"; } else { psstate = "1"; } // println psname+" - "+psdescr+" - "+psstate; } if (it.startsWith("\tfan")) { fannamestoken = it.split(" at "); fanname = fannamestoken[0]; fanname = fanname.trim(); fanname = fanname.replace("\t", ""); fandescr = fannamestoken[1]; fandescr = fandescr.split(" of"); fandescr = fandescr[0]; fandescr = fandescr.trim(); fandescr = fandescr.replace("\t",""); fanstate = it.split(","); fanstate = fanstate[0]; fanstate = fanstate.split(": "); fanstate = fanstate[1]; fanstate = fanstate.trim(); fanstate = fanstate.replace("\t", ""); if (fanstate == "ok") { fanstate = "0"; } else { fanstate = "1"; } fanspeed = it.split("speed: "); fanspeed = fanspeed[1]; fanspeed = fanspeed.trim(); fanspeed = fanspeed.replace("\t", ""); fanspeed = fanspeed.replace("rpm", "") //println fanname+" - "+fandescr+" - "+fanstate+" - "+fanspeed; println "${arraydesc}##${fanname}######" println "auto.nimble_array_fan_description=${fandescr}" println "auto.nimble_array_grouptype=fan" println "${arraydesc}##${fanname}######.Status=${fanstate}"; } } cli.send("exit \n\r") cli.expectClose()
When I test the script and choose say the A controller I get this as the output.
LabNimble02-A##fan1###### auto.nimble_array_fan_description=front auto.nimble_array_grouptype=fan LabNimble02-A##fan1######.Status=0 LabNimble02-A##fan2###### auto.nimble_array_fan_description=front auto.nimble_array_grouptype=fan LabNimble02-A##fan2######.Status=0 LabNimble02-A##fan3###### auto.nimble_array_fan_description=rear auto.nimble_array_grouptype=fan LabNimble02-A##fan3######.Status=0 LabNimble02-A##fan4###### auto.nimble_array_fan_description=rear auto.nimble_array_grouptype=fan LabNimble02-A##fan4######.Status=0