0 votes
3.1k views
in Javascript API by (120 points)

Hello Everyone: @ BPM Guys, 

I need a support in a POC of IBM BPM from the community, below are the requirements that needs to be achieve: 

  •   Connection with extrernal host/server using script in BPM BPD service
    share any sample script for that ?
  • Execute some shell script commands after the authentication from code side in BPM. 
    below is the sample command: 

 <!--[endif]-->tabcmd export "ARRAZIARRAZI-VDashboard/SensorPlotDashboard?Sensor%20Name%20-%20running_feedback&Model=Fan%20NDE%20Bearing" --png --width 1900 --height 800  -f "C:\AHC_Alert.png"

Please share guidelines if there are any way arounds to achieve this in IBM BPM. 
This can be done easily from the other frameworks or tools (i.e. DOT NET, C#) but I need to do the same using IBM BPM process/service. 

I would appreciate for the prompt response from the community gurus. 

Thanks & Regards,

Imtiaz Ahmed  

1 Answer

0 votes
ago by (30.6k points)

BPM / BAW cannot open an SSH session by itself, but a service flow can run Java, and Java can run PowerShell remoting or SSH. Three practical designs:

1. Java integration + SSH library (JSch or Apache MINA sshd as a managed server file jar): the service flow calls a small Java class that opens the SSH connection and runs the command; on a Windows host run PowerShell through the OpenSSH server (powershell -Command ...).

// Java class packaged as a managed jar, called from a Java Integration in a service flow
public class RemoteShell {
  public static String run(String host, String user, String password, String command) throws Exception {
    JSch jsch = new JSch(); Session s = jsch.getSession(user, host, 22);
    s.setPassword(password); s.setConfig("StrictHostKeyChecking", "no"); s.connect(15000);
    ChannelExec ch = (ChannelExec) s.openChannel("exec"); ch.setCommand(command);
    InputStream in = ch.getInputStream(); ch.connect();
    String out = new String(in.readAllBytes(), "UTF-8"); ch.disconnect(); s.disconnect(); return out;
  }
}
// service flow script: tw.local.output = result of the Java integration "run"
// input mapping: host = tw.env.remoteHost, command = "powershell -NoProfile -Command Get-Service -Name Spooler | ConvertTo-Json" 

2. Expose PowerShell as a REST end point on the host (Windows: a tiny Flask / .NET minimal API, or PowerShell Universal) and call it with the OOB REST external service from BAW - no Java, no credentials in BPM, and the host controls what may be executed. This is the option security teams usually prefer.

3. UCA + queue: the BPD sends a JMS / MQ message with the command request, an agent on the host consumes it and answers with a message that the BPD receives through a UCA - fully asynchronous and auditable.

Whatever you choose: store the credentials in a Server definition or an environment variable of the app (never in the script), restrict the commands to a fixed list on the host side, and put a timeout on the call (service flows block a thread while waiting).

References

Related questions

0 votes
1 answer 2.1k views
0 votes
2 answers 3.4k views
0 votes
1 answer 1.2k views
0 votes
1 answer 1.0k views
0 votes
1 answer 665 views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...