ExternalParameterShellExec DCI not working [Solved]

Started by BlackMamba, June 21, 2013, 01:56:17 PM

Previous topic - Next topic

BlackMamba

Hi to all.
After configuring in the right way the ExternalParameterShellExec, here, I decided to run a test script and to collect the script's result using a DCI.
So, in my Data Collection Configuration I can set ProvaExternal as DCI collected by NetXMS Agent but the data type expected is different from the one I expect to obtain from the script (the script should return an int but Data Type in NetXMS is set as String). Anyway, this isn't the main issue. My script is written in perl. It should write a string on an hypothetical log file (already created) and, once the the file is closed, it should return an int but, opening the log file, I understood that nothing is written on the file. The standalone script works, I've tested it. My agent configuration file is:

MasterServers = XXX, YYY
EnableSubagentAutoload = yes
LogFile = /var/log/nxagentd.log
FileStore = /tmp
ListenAddress = 0.0.0.0
EnableActions = yes
SubAgent=portcheck.nsm

ExternalParameterShellExec=ProvaExternal:/PATH/WriteLog.pl


Instead, the script WriteLog.pl (now I'm trying without return value) is:

#!/usr/bin/perl
use Time::localtime;

open(LOG,">>", "/PATH/hdsl_monitoring_script.log");
print LOG ctime().":start test \n";
close LOG;

Still nothing written in "hdsl_monitoring_script.log". Any suggestions? What is going wrong?

Victor Kirhenshtein

Hi!

Do you configure DCI for ProvaExternal parameter? Can you run agent in debug mode and check if server requests this DCI and what happens with external script execution?

Best regards,
Victor

BlackMamba

Yes, I did.
Once edited the the agent configuration file, I configure the DCI for ProvaExternal, as you can see in the attachments ParameterSelection, ExternalParameterDCIProperties and DCIExternalParameter. I also run the agent in debug mode, attachments ExternalParameterDebug is bash's output I obtain. As I expected, the request is processed in the right way, but the script doesn't run.
In this post it's written:
Quote
Pay attention that in bash the value is returned using echo which in perl, this value is returned by printing out to the standard output. Do not use exit or return.

Pay attention... starting your script by /usr/bin/perl my_mon_script.pl will not call a bash... while ./my_mon_script.pl does! Taouw... as Homer says
I didn't understand well this two lines! If I want a return state I should use a print? If yes, will it be processed as a int or as a string? For example this two codes:
1) #!/usr/bin/perl
use Time::localtime;

open(LOG,">>", "/PATH/hdsl_monitoring_script.log");
print LOG ctime().":start test \n";
close LOG;
print "ok";


2)
#!/usr/bin/perl
use Time::localtime;

open(LOG,">>", "/PATH/hdsl_monitoring_script.log");
print LOG ctime().":start test \n";
close LOG;
print 0;

will be processed in the same way?
I'm on Xubuntu so I have to start my script using "#!/usr/bin/perl". But the post says I should start my script with ./NAME_OF_THE_FILE.pl? Should I set file's permissions to be executed as a program?

BlackMamba

IT WORKS!!

I just had to set the flag "Allow the execution as a program" in the script->proprieties->permissions table!

Here are some tips for a configuration working on Xubuntu (or Debian based) and a perl script:
1) To set up the External Parameter follow this post. Remember the poll->configuration passage!
2) Once you set up your External Parameter, be sure that the script is allowed to run as a program (either by GUI or shell) and that your script starts with #!/usr/bin/perl.
3) Set up your DCI remembering that ending your script with "print 1;" will return an int and "print "ok";" will return a string.
4) Check always the right paths and if everything has the "sudo" permissions if you have to execute root operations.
5) It's possible to create multiple ExternalParameterShellExec. Just repeat the (1) point by appending the new parameters and then you can set up the DCI.