- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2015 08:07 AM
Hi All,
I have buit a probe and sensor to a Linux Machine for Discovery purpose for disk space.
Command used : "fdisk -l | grep GB | awk '{print $3}' | paste -sd+ - | bc" Sudo : Required.
Sometimes for a few machines we get the input from the probe (command out put) we get the below output :
Disk /dev/dm-0 doesn't contain a valid partition table Disk /dev/dm-1 doesn't contain a valid partition table Disk /dev/dm-2 doesn't contain a valid partition table Disk /dev/dm-3 doesn't contain a valid partition table Disk /dev/dm-4 doesn't contain a valid partition table Disk /dev/dm-5 doesn't contain a valid partition table Disk /dev/dm-6 doesn't contain a valid partition table Disk /dev/dm-7 doesn't contain a valid partition table Disk /dev/dm-8 doesn't contain a valid partition table Disk /dev/dm-9 doesn't contain a valid partition table 321.2
the last few characters are the disk space.
And the sensor i have built is below : There is no error in the below sensor when i check in the syntax checker, and the javascript code gives correct output when we i check the code with the input from the probe, but if the same code below is not updating the CMDB attribute.
new DiscoverySensor({
process: function(result) {
if (gs.nil(result.output))
return;
this.parseOutput(result.output);
},
parseOutput: function(output) {
var a = output.trim();
var b = a.slice(-8);
var c = b.match(/\d+/);
current.disk_space = c.trim();
},
type: "DiscoverySensor"
});
Can someone hemp me where the error is ? I am stuck at this point on this.
Solved! Go to Solution.
- Labels:
-
Discovery
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2015 12:02 PM
So what you had there was a "problem" that we call a "feature" described in this community post org.mozilla.javascript.NativeArray@... as CI Name when discovering ESX Hosts
You were getting the same issue with that Native Array@ being populated in the field so Ryan rzulli and I had some fun this afternoon and re-wrote the sensor.. you'll see it attached to your probe .. We decided to just loop through the lines and reject the ones that contained disk and took the value at the end..
new DiscoverySensor({
process: function(result) {
if (gs.nil(result.output))
return;
this.parseOutput(result.output);
},
parseOutput: function(output) {
var lines = output.split(/\n/);
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
var disk = line.indexOf("Disk")
if (disk === 0)
{
continue;
}
else
{
current.disk_space = line;
}
}},
type: "DiscoverySensor"
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2015 02:26 PM
try using gs.log to make sure the values are being passed down as expected.. for example
parseOutput: function(output) {
var a = output.trim();
gs.log("This is A =" + a);
var b = a.slice(-8);
gs.log("This is B =" + b);
var c = b.match(/\d+/);
gs.log("This is C =" + c);
current.disk_space = c.trim();
Slip those log statements inbetween and run.. Check script log statements for the output.. very helpful!
Or
If its feasible have you tried different commands that would be easier to parse such as
#df -h --total | grep total
total 53G 4.5G 47G 9%
Which returns
Size Used Avail Use%
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2015 02:16 AM
Hi Doug Schulze,
I gs.log for checking the value calcualtions, and below is the log
calculations are correct, only the last step where the CI is updated is having problem.
I have tried the same code by hard-coding the value as below
current.disk_space = "100" and this is working,
only the value calculated from the above is not working at the time of passing the values to the CI. I am unable to find why this is happening.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2015 09:01 AM
Can you PM me what instance you are on?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2015 03:47 AM
Hi Doug Schulze,
I am unable to send any message to you.. (I have accepted the invite).
Can you please message/mail me.. I will reply to that message.
Thanks,
Ananth