-
1. How to execute psl code remotely?
Jonathan Coop Feb 9, 2011 1:37 AM (in response to Rohit NameToUpdate)1 of 1 people found this helpfulHi Rohit
The way I do this is to have two KM's one at the remote end, and the other locally, I pass arguments on the outgoing event, with username, password, and hostname to log back to. Then I trigger a remote event, to the remote client, the class of the event has defined a Notification script defined.
Below is some code I've used to send back a count of processes running back to the local machine, note that the code runs as a notification script in the event class definition. It is UNABLE to write to the system console, hance the degug output to file. Note that this code has some support for domain accounts.
hdl=fopen(getenv("PATROL_TEMP")."/CrossMCProcMon_err.txt","a");
# The args passed are as follows
# inst,ownerLocal,returnDomain,returnUser,returnPasswd,returnHost,returnPort,localProcs;
all_args="%{EV_ARGS}";
ct=0;
inst=replace(nthargf(all_args,++ct,""),"<null>","");
ownerLocal=replace(nthargf(all_args,++ct,""),"<null>","");
returnDomain=replace(nthargf(all_args,++ct,""),"<null>","");
returnUser=replace(nthargf(all_args,++ct,""),"<null>","");
returnPasswd=replace(nthargf(all_args,++ct,""),"<null>","");
returnHost=replace(nthargf(all_args,++ct,""),"<null>","");
returnPort=replace(nthargf(all_args,++ct,""),"<null>","");
#put back any spaces
localProcs=replace(ntharg(all_args,int(++ct)."-",""," "),",","\n");
count=getProcCount();
#If we cannot send info back, we can only report to file, cannot print to sys console, not send an event back!.
if (returnDomain=="") {
sessID=remote_open(returnHost,returnPort,"DES",returnUser,returnPasswd);
error=errno;
}else{
sessID=remote_open(returnHost,returnPort,"DES",returnDomain."\\".returnUser,returnPasswd);
error=errno;
}
close(hdl);
if (sessID=="") {
hdl=fopen(getenv("PATROL_TEMP")."/CrossMCProcMon_err.txt","a");
if (hdl != "") {
#If the handle is null we're stuffed, nowhere to write to!
#write(hdl,"All args is: **".all_args."**\n");
write(hdl,asctime(time(),"%d/%m/%Y %H:%M:%S")." Unable to send info to ".returnHost." on port ".returnPort." user ".returnUser." domain ".returnDomain."\n");
write(hdl,"Error given (see PSL ref manual 1 for decode): ".error."\n");
close(hdl);
}
exit;
}
res=remote_event_trigger(sessID,get("/name").".".inst,"CrossMCProcMon_CONTAINER","handleResults","INFORMATION","2",inst,count);
if (res=="") {
hdl=fopen(getenv("PATROL_TEMP")."/CrossMCProcMon_dbg.txt","a");
if (hdl != "") {
#If the handle is null we're stuffed, nowhere to write to!
write(hdl,asctime(time(),"%d/%m/%Y %H:%M:%S")." Trying to send event to ".returnHost." on port ".returnPort." user ".returnUser." domain ".returnDomain."\n");
write(hdl,"Count was ".count." for process ".inst." process string ".localProcs." owner ".ownerLocal."\n");
close(hdl);
}
}
remote_close(sessID);
Below is code to trigger the previous:
res=remote_event_trigger(sessID,"countRemoteProcs","CrossMCProcMon_CONTAINER","countProcs","INFORMATION","2",inst,ownerRemote,thisDomain,thisUserName,thisPasswd,thisHost,thisPort,remoteProcs);
I'd post the entire code but I don't have documentation, which would seem unfair on anyone trying to use it!.
Hope this helps
Jon
-
2. How to execute psl code remotely?
Jonathan Coop Feb 9, 2011 2:25 AM (in response to Jonathan Coop)I think you can also use remPSL event, but I believe the entire code to be passed has to go in the first argument, the results get posted remotely which you then have to query and bring back.
The second argument you pass to remPSL is a unique identifier that you pass to identify the correct result.
Jon
-
3. How to execute psl code remotely?
Rohit NameToUpdate Feb 9, 2011 10:48 PM (in response to Rohit NameToUpdate)Hey thanks joncoop2. Your suggestion seems to be helpful. Let me try this and then I'll again get back to you.
-
4. How to execute psl code remotely?
Rohit NameToUpdate Feb 22, 2011 1:15 PM (in response to Rohit NameToUpdate)Hi Jon,
I did coding using remPSL event, and it really worked. But when I am giving .psl file as input to
remote_event_trigger(......) , then it executes only first line.
I need the whole to be executed correctly.
Suppose if have
i=1;
while(i<5)
{
i++;
}
print(i);
then it should return 5 as output on remote machine.
My code is
sessionID=remote_open("machine-name","3181","NONE","administrator","password");
print(sessionID);
chan=fopen("/tmp/test1.psl","r");
tes=read(chan,100);
print(tes);
if(sessionID)
{
your_id = "my_id";
remote_host="machine-name";
trigger_res = remote_event_trigger(
sessionID,
remote_host,
"STANDARD",
"RemPsl",
"INFORMATION","5",
tes,
your_id
);
print("Result of trigger->".trigger_res."\n");
if(trigger_res)
{
query_res=remote_event_query(
sessionID,
"1",
1,
"",
"%{EV_ARG1}\n",
"","",
"",
"",
"",
"",
your_id,
"",
""
);
print("Result of query->".query_res."\n");
}
remote_close(sessionID);
}
-
5. How to execute psl code remotely?
Jonathan Coop Feb 22, 2011 1:25 PM (in response to Rohit NameToUpdate)Hi
I don't think your code will work because print, will not work when carried out this way, instead write to a file remotely and try that.
Mind I don't use RemPSL, as my original post shows, remote triggering of events will not print to the System Output window.
Regards
Jon
-
6. How to execute psl code remotely?
Rohit NameToUpdate Feb 23, 2011 4:30 AM (in response to Jonathan Coop)I was trying to execute it as psl task.
It works perfectly fine but executes only 1st instruction of file. How could I execute the complete program in intact way?
-
7. Re: How to execute psl code remotely?
Jonathan Coop Feb 23, 2011 7:49 AM (in response to Rohit NameToUpdate)Hi Rohit
Have you tried executing a remote PSL script without print statements?.
If you have can you show such script, if you need to output data within your
program write to file.
Jon
-
8. Re: How to execute psl code remotely?
Geert De PeuterFeb 23, 2011 8:10 AM (in response to Rohit NameToUpdate)
Here is a trick to execute multiple psl through RemPsl
Let's say your script is
output = "";
for (i = 0; i < 10; i++) {
output = output." ".i;
}
Then you have 2 problems
- Multiline script does not work with RemPsl (at least without this trick)
- There is no support for returning a variable
A solution for this problem is rather simple
- start your script with xxx_pem = 0;
- then have your script
- copy the output in the xxx_pem variable
So the script will become something like :
xxx_pem = 0;
output = "";
for (i = 0; i < 10; i++) {
output = output." ".i;
}
xxx_pem = output;
And it will just work.
-- Geert
PS: For the purists ... as an alternative to the first line you can have 0; as well
So the following will also work :
0;
output = "";
for (i = 0; i < 10; i++) {
output = output." ".i;
}
xxx_pem = output;
- Multiline script does not work with RemPsl (at least without this trick)