sitescope.js
2.52 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
/*************************** LILOM JavaScript ***************************/
/** The lilom.jar file must be deployed in the <package path>\lib dir ***/
/** on the sitescope server installation, otherwise the import will *****/
/** fail and the Utils class cannot be found ****************************/
/************************************************************************/
// Java imports
importPackage(java.lang);
importPackage(com.lil.om);
// Connection String to Oracle for this monitor (format is hostname:port:sid:user:pass)
var con = encodeURIComponent("vmorasrv:1521:XE:system:Passw0rd");
// Where to find the OraMonREST service
var oramonsrv = "http://localhost:8989/OraMonREST";
// Age that we allow for the data (for caching)
// Set to 0 to force update of data on each monitor run. Set to one second less than the Monitor Run Settings Frequency in seconds for normal use.
var age = 14;
// Creates an object of a custom Java Utils class defined in lilom.jar
var utils = new Utils();
var json, result;
try {
result = utils.wget(oramonsrv+"/getData?connectionString="+con+"&age="+age);
json = JSON.parse(result);
if(json.error == false) {
result = utils.wget(oramonsrv+"/getMetrics?connectionString="+con);
json = JSON.parse(result);
if(json.error == false) {
// We have results, create the monitors
for(var i=0; i < json.nvarray.length; i++) {
myContext.getScriptResult().setValue(json.nvarray[i].name, json.nvarray[i].value);
}
myContext.getScriptResult().setAvailability(true);
myContext.getScriptResult().setSummary("Success");
} else {
myContext.getScriptResult().setAvailability(false);
myContext.getScriptResult().setSummary("Error3: " + json.msg);
}
} else {
myContext.getScriptResult().setAvailability(false);
myContext.getScriptResult().setSummary("Error2: " + json.msg);
}
} catch (e) {
myContext.getScriptResult().setAvailability(false);
myContext.getScriptResult().setSummary("Error1: " + result);
}
// Logger for debug messages. The logger writes messages to <SiteScope>\logs\custom_monitors\custom_monitor.log
//var logger = myContext.getMonitorLog();
//logger.info("debug string");
/*********************************************************************************/