Repository navigation
Expand file tree
/
Copy pathStatus.js
More file actions
102 lines (78 loc) · 3.22 KB
/
Copy pathStatus.js
File metadata and controls
102 lines (78 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Author: Dominick G. Peluso < www.linkedin.com/in/dominickpeluso >
Date: September 11, 2014
Copyright © 2014
Creates a bash script that executes a cURL to a DFE which returns a
status response JMF.
-----------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
function jobArrived( s : Switch, job : Job )
{
// Set flow element variables
var detailType = s.getPropertyValue('DetailType');
var deviceUrl = s.getPropertyValue('DeviceURL');
var responseDataSetName = s.getPropertyValue('ResponseDataSetName');
var debugLevel = s.getPropertyValue('DebugLevel');
// Build JMF
var request = '<?xml version="1.0" encoding="UTF-8"?>' +
'<JMF xmlns="http://www.CIP4.org/JDFSchema_1_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SenderID="MIS System" TimeStamp="2006-04-19T17:47:10-07:00" Version="1.2">' +
'<Query ID="misb4c3c9f88d02c8ea" Type="Status" xsi:type="' + detailType + '">' +
'<StatusQuParams DeviceDetails="Details" />' +
'</Query>' +
'</JMF>';
// Build shell script
var script = '#!/bin/sh' + '\n\n' +
"curl -X POST -d '" + request + "'" + ' --header "Content-Type: application/vnd.cip4-jmf+xml" ' + deviceUrl '\n' +
'echo';
// Make temp shell script file
var temp_shell_script = job.createPathWithName( job.getNameProper() + '_exec.sh' );
var shellFile = new File(temp_shell_script);
// Write to shell script
shellFile.open(File.WriteOnly);
shellFile.write(script);
shellFile.close();
// Make the temp file writeable
var String args = new Array();
args[0] = "chmod";
args[1] = "777";
args[2] = temp_shell_script;
var exitStatus = Process.execute(args);
// Process the temp shell script
var String args = new Array();
args[0] = temp_shell_script;
var exitStatus = Process.execute(args);
// Grab some variables
var curlResponse = Process.stdout;
var curlError = Process.stderr;
// Write private data
//job.setPrivateData(ResponsePrivateDataKey, curlResponse);
// Save as data set
var responseDataset = job.createDataset('XML');
var responseDatasetPath = responseDataset.getPath();
var datasetResponseFile = new File( responseDatasetPath );
datasetResponseFile.open(File.WriteOnly)
datasetResponseFile.write(curlResponse);
datasetResponseFile.close();
job.setDataset(responseDataSetName, responseDataset);
// Finish
job.sendToData(1, job.getPath());
job.sendToLog(1, temp_shell_script);
// Log
if(debugLevel == 1){
s.log(2, script);
s.log(2, curlResponse);
s.log(2, curlError);
s.log(2, temp_shell_script);
}
}