Is is possible to call a Powershell script from the REST API

Ask and answer questions related to any type of OSA scripting.
Post Reply
Message
Author
Andre
Posts: 26
Joined: Tue Jul 08, 2014 6:29 am

Is is possible to call a Powershell script from the REST API

#1 Post by Andre » Mon Nov 24, 2014 8:50 am

Hi,

I have tried many ways of calling a PowerShell script from the REST interface, but I cannot seem to get it right.

Is this possible and if so, what is the syntax?

Based on the help in http://www.opensourceautomation.com/wik ... title=REST and http://localhost:8732/api/help,
I would expect the below to work, but it returns a"True", but I don't see anything happening in OSA.

http://localhost:8732/api/object/PowerS ... m1=SayTime

Does anyone know if this is possible? I can call Pattern Matches fine, but I don't feel that this is the correct place to be calling these scripts.

Any help would be appreciated. If I have missed something similar in the forum, please direct me to to it

Andre

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Is is possible to call a Powershell script from the REST

#2 Post by Automate » Mon Nov 24, 2014 9:05 am

I agree that you should be able to directly call a script but that's not how it's currently set up. We've talked about adding this feature but it's not done yet.

Currently you have to create a pattern that points to the script and also a "pattern match" that points to the pattern.

Then use http://yourosaserver:8732/api/namedscript/{your pattern match name}

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Is is possible to call a Powershell script from the REST

#3 Post by Automate » Mon Nov 24, 2014 9:23 am

Well, in looking again at your REST command I'm not sure why it does not work. "SayTime" is the name of your script right?

Can you run the same PS script from the OSA Objects web page?

Does anything show up in the OSA logs?

Vaughn
Site Admin
Posts: 1432
Joined: Thu May 13, 2010 2:17 pm

Re: Is is possible to call a Powershell script from the REST

#4 Post by Vaughn » Sat Dec 13, 2014 6:03 pm

Pattern Matches in a way are supposed to be Friendly names for scripts that allows for many ways to call them. I think just another area were more work is needed to make them tied together right and for it to be more obvious. The goal of openness complicates things, so in trying to make the patterns more useful than just script alias, it broke using it as script alias to a degree.

I think the intended solution here was new scripts would automatically generate the patterns to call them... If this was done, there would not be a need for two separate calls... Calling a pattern should be much preferable to calling a script name directly, I think it just needs to automate a little of the work that makes it happen on the backend.

Vaughn

User avatar
Mat
Posts: 501
Joined: Thu Aug 09, 2012 2:35 pm
Location: UK

Re: Is is possible to call a Powershell script from the REST

#5 Post by Mat » Sun Dec 14, 2014 4:12 pm

Hi Andre,

You will always get true returned from that Rest method your calling, however if the method isn't added to the queue for processing you see a message in the log. which will contain "API - MethodQueueAdd error". Are there any logs from the Powershell plugin? either containing "running script:" or "Error Processing Command"?

Andre
Posts: 26
Joined: Tue Jul 08, 2014 6:29 am

Re: Is is possible to call a Powershell script from the REST

#6 Post by Andre » Mon Dec 15, 2014 9:12 pm

I seem to have missed your second post Automate, sorry for not replying sooner.

I have just relooked at this and find the calling PS scripts from the REST interface is now working perfectly, with my original syntax.

It must has been a "can't see the forest for the trees" type of problem. :roll:

Thanks for the help.

In case anyone else needs it, the cURL syntax to call a Script from the REST interface is:-

Code: Select all

curl --data -h "http://{IPAddressofOSA}:8732/api/object/PowerShell/Run%20Script?param1={scriptname}&param2={parameter}"
and to call from a Python script

Code: Select all

#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "--data" ,'-H', "http://{IPAddressofOSA}:8732/api/object/PowerShell/Run%20Script?param1={scriptname}&param2={parameter}"])

Post Reply