Forum Discussion

Lewis_Beard's avatar
3 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
cli=Expect.open(host, user, pass) //connect
cli.expect(prompt) //Waiting for prompt...


// send the command
println(ds_command);
cli.send(ds_command);
cli.expect(prompt);

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

println("WHATGIVES1\n");
println(cmd_output);
cmd_output.eachLine {line ->
    println("moo\n");
}

println("WHATGIVES2\n");

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

//exit session
cli.send("exit\n");

println(site);


return 0

  • Anonymous's avatar
    Anonymous
    3 years ago

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

  • 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.

  • Anonymous's avatar
    Anonymous

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