Sensor script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2017 12:10 PM
Hello Community,
I have the following output that I am trying to capture the output for "Not After":
<?xml version="1.0" encoding="UTF-8"?><results probe_time="164"><result><output>Certificate:
Data:
Version: 3 (0x2)
Serial Number: 132 (0x84)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=US, ST=Hawaii, O=State of Hawaii, OU=Department of Human Services, CN=inter-ca
Validity
Not Before: Oct 17 02:25:35 2013 GMT
Not After : Oct 15 02:25:35 2023 GMT
I need help with the following script to parse the output:
new DiscoverySensor({
process: function(result) {
if (gs.nil(result.output))
return;
this.parseOutput(result.output);
},
parseOutput: function(output) {
var updated = false;
var lines = output.split(/\n/);
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line == '')
continue;
var parts = line.split(" : ");
var name = parts[0].trim();
var value = parts[1].trim();
if (name == "Not After")
current.u_ssl_exp = value;
}
},
type: "DiscoverySensor"
});
Any help would greatly be appreciated.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2017 01:02 PM
Did you try trimming name too before checking
if (name == "Not After")
Reason, I see a space getting into array[0] for "Not After ". What is your output when ran above code?
Keep gs.log("The name is "+name+" and length is "+ name.length); just above above if condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2017 01:29 PM
isn't the name already being trimmed via:
var value = parts[1].trim();
for the log does this look correct to what you are advising?
gs.log("The name is "+name+" and length is "+ name.length);
if (name == "Not After")
current.u_ssl_exp = value;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2017 01:38 PM
I tried to put the log script but nothing was captured in the system logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2017 02:48 PM
Could be an error throwing before.
Can you log multiple gs.log(" Begin >>> "); across code lines? just to make sure where script breaking.
also put a statement at line 12
gs.log("Not After Index check >>>> "+output.indexOf("Not After"));