Forum Discussion

Lewis_Beard's avatar
2 years ago

Custom datasource send/expect .before() issue .... empty data

I'm trying my hand at a custom datasource just to do a proof of concept. The part of it that generates instances is correct, and most of the code seems correct, I'm making a datapoint that is just the output, or thats the goal.

I'm using ssh and send and expect and the .before() as in the LM examples and my issue is that I KNOW my code is working and the prompts are working and etc, because when I add a touch command in there, I'm seeing the file appear on the serevr.

But for some reason the .before() command isnt grabbing anything. No data. But it SHOULD have captured the response to my real command I care about, which is an nslookup.

The code is short, I see all my values and println stuff coming back in the test window, and I see the "touch" command I slipped in there working on the server. But the cmd_output I've captured with .before() is empty.

Is there something fundamentally wrong I'm doing?


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.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

host = hostProps.get("system.hostname")
user = hostProps.get("ssh.user")
pass = hostProps.get("ssh.pass")
prompt = "^.+?>\\s+"

site = instanceProps.get("wildvalue")
wildvalue2 = instanceProps.get("wildvalue2")
ds_command = "nslookup $site\n"

//ssh into the device, user, pass) //connect
cli.expect(prompt) //Waiting for prompt...

// send the command

//get everything from the first prompt to the second prompt
cmd_output = cli.before();

cmd_output.eachLine {line ->


cli.send("touch /tmp/abctouch444.txt\n");

//exit session


return 0

  • I can't see anything obviously wrong. You might try printing cli.sdtout() to see if it contains more helpful information. Documentation here.

2 Replies

  • Thanks. I can println(cli.stdout()) and I see it all and it works perfectly, i see all my command results.

    So I may just use stdout() to snag the response or interact with it. I have no idea why .before() doesnt work. Maybe I have to convert it to a string or something.

    Anyway, stdout is all good, so I appreciate the pointer to those docs, and the suggestion.