Forum Discussion

Justin_Lanoue's avatar
3 months ago

ConfigSource for Linux Files.

I'm having trouble figuring this out.

How would I create a ConfigSource to cat the output of an ubuntu file and store that into ConfigSource?

I've been able to get the output if I specify just cat the command and expect the last line in the config but their examples don't work when the my shell prompt is "user@hostname~$".

https://www.logicmonitor.com/support/logicmodules/articles/creating-a-configsource#general

https://www.logicmonitor.com/support/terminology-syntax/scripting-support/groovy-or-expect-text-based-interaction#

import com.santaba.agent.groovyapi.expect.Expect;

host = hostProps.get("system.hostname")
user = hostProps.get("test.user")
pass = hostProps.get("test.pass")

cli=Expect.open(host, user, pass)
cli.send("clear\n")
cli.send("cat test.conf\n")
cli.expect('~\$')
config=cli.before()
println config;

I've tried many combinations and I'm also not sure on how to remove the shell text information before the command such as the MOTD and system information.

  • If you echo "---------------------------" before and after the file, you can use split and pull out the 1th element (zero-indexed).

    Example:

    import com.santaba.agent.groovyapi.expect.Expect;
    host = hostProps.get("system.hostname");
     user = hostProps.get("test.user");
    pass = hostProps.get("test.pass");
    cli=Expect.open(host, user, pass);
    cli.send("echo \"----------------------------------------\"\n");
    cli.send("cat test.conf\n");
    cli.send("echo \"---------------------------------------END\"\n");
    cli.expect('---END');
    config=cli.before();
    println config.split('---------------------------------------')[1];

     

  • We use the SFTP option to get the files actually. We are already monitoring via SSH.

    We add the sftp.files property with the full path to the file. For example we could have "/etc/sysconfig/iptables" set and it will simply sftp the file.

     

     

    • Justin_Lanoue's avatar
      Justin_Lanoue
      Icon for Neophyte rankNeophyte

      Thanks, I didn't know that this existed.

      Although, I'm not able to get this to work. It always says "No such file or directory"

      sftp.files = /tmp/test.conf

      ls -l /tmp/test.conf 
      -rw-rw-r-- 1 user user 9 Nov 12 20:22 /tmp/test.conf

      Error!
       
      The script failed, elapsed time: 0 seconds - java.io.IOException: No such file or directory
      java.lang.RuntimeException: java.io.IOException: No such file or directory
      at com.logicmonitor.groovy.objects.BaseWrapper.invoke(BaseWrapper.java:124)
      at com.logicmonitor.groovy.objects.lang.ScriptWrapper.run(ScriptWrapper.java:31)
       
      Any assistance would be greatly appreciated.
      • Joe_Williams's avatar
        Joe_Williams
        Icon for Professor rankProfessor

        This sounds like a permission issue but your tmp test should have worked.
        Honestly, all we did was add the sftp.files property with our few files and it worked.