Discovery Sensor

ananthn
Kilo Contributor

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.

1 ACCEPTED SOLUTION

doug_schulze
ServiceNow Employee
ServiceNow Employee

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"



  });


View solution in original post

12 REPLIES 12

doug_schulze
ServiceNow Employee
ServiceNow Employee

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%


Hi Doug Schulze,



I gs.log for checking the value calcualtions, and below is the log


find_real_file.png



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.


doug_schulze
ServiceNow Employee
ServiceNow Employee

Can you PM me what instance you are on?


ananthn
Kilo Contributor

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