How to create custom probe and sensor.

Creating custom probe and sensor.

Before starting this I assume you already know what is probe and sensor and what does it do.If you are not aware of probe and sensor then please go through this link first Probes and Sensor.

Here we will try implementing a very small and basic requirement. Once you understand how it works you can implement any complex requirement also. So here we will try to fetch the BIOS information of a windows system and will populate this result into the BIOS detail field ( which is a custom field that I have created ) of CI table .



Let's start with probe first :-

To create a probe follow the below steps :-

1. Under Discovery definition click on probes module.


2. Give a meaningful name to the probe. Ex. Windows-BIOS version.

3. The value in the ECC queue topic field appears in the ECC queue output record's "topic" field when this probe is launched.Since its a DOS command write Command in the field. Please note it's case sensitive so if you will write command it will not execute.

4. If your command that needs to be executed is small and concise then you can enter your command directly into the ECC queue name field. Write systeminfo|find "BIOS Version"  in this field

5. Now save the record and click on the test probe related list and provide and provide the IP address of the windows device and select the proper midserver. Click on ok button



After probe gets executed you will be redirected to ecc_queue table with two entries. First record whose "Queue" value is output is the probe which went to the midserver along with the command that we wanted to execute. In our case it is " systeminfo|find "BIOS Version ".



 The second probe whose "Queue" value is input is the one that was sent by the midserver to the servicenow along with the result. Open this record and look inside the payload field. You will see the output of your command is carried inside the result tag.



By now we have completed half of our work. 

So what all we have accomplished by now as per our requirement ? The answer is by now we have created a probe which contains the command to extract the BIOS information of the device. Executing this probe successfully brings the BIOS information back to the servicenow tool.

Now we need someone who can use this result and insert this information into the BIOS detail field ( which is a custom field that I have created ) of the CI whose BIOS information we have extracted.

Here comes the Sensor which does this job.


To create a sensor follow the below steps :-


1. Under Discovery definition click on sensor module.

2. Give a meaningful name to the sensor. I am giving the same name Windows-BIOS version so that one can easily understand for which probe this sensor related to.

3. In "Reacts to Probe" field select the probe you just created i.e. Windows-BIOS version

4. In the script filed we write the javascript which extracts the <stdout> tag value from the result. For this first we create the object of DiscoverySensor class. Each sensor initiates a new object using DiscoverySensor class. If you open this script include then you might find it very complex to understand but for simple situations, you only need to create the process function. In the below code we have created the cobject of DiscoverySensor class. In process function the result parameter contains the output returned by the probe.

new DiscoverySensor({
    process: function(result) {
        // API shell -- every probe needs a sensor
    },

    type: "DiscoverySensor"
});

3. Now if you see the output that came back to the servicenow  "BIOS Version:              LENOVO 9ACN29WW, 10/20/2014" you will notice that we need to modify this data before inserting this into the field. For this purpose we will use javascript code.

new DiscoverySensor({
    process: function(result) {
        // API shell -- every probe needs a sensor
var output=result.stdout;//stdout is the tag that contains the output of the command
var bios_result=output.split(":")
current.u_bios_detail=bios_result[1];  //assigning the result into the BIOS detail field.
    },

    type: "DiscoverySensor"
});


Now we are done with creation of probe and sensor. Now one final work is left to make it fully functional. We need our probe to attach so that it can run every time discovery runs of Windows device. To do this go to Discovery Definition > CI Classification >windows. Open the windows record which is for cmdb_ci_computer table.




Go to Triggers pobes related list and click on edit.



Select your custom probe Windows-BIOS version.



Now we are done with every thing. Cross your fingers now because now is the time to test......

Go to Discovery Schedules click on Quick Discovery button in the dialog box opened enter the IP address of the window device select your midserver and click on OK button. Let the discovery complete. 

Once discovery gets competed one the device from device related list and check the BIOS detail field. You will see the filed populated with the value.





I hope you will find this post helpful. Please give your feedback in the comments. Thankyou










Comments

  1. use more tags and use different theme to make a good user interface.

    ReplyDelete
  2. Really awsmm document thks alot...

    ReplyDelete
  3. Exactly what I was looking for. Excellent and to the point topic.

    Thank you very much.

    Rajan

    ReplyDelete
  4. Hello Kamlesh,

    Quick question. I used your blog and created a custom Probe to execute systeminfo command and I noticed that every time I run the discovery, it brings me the same results. Then I realized, that it is bringing results of MID server. Is there any step I might be missing?

    Please advise.

    Thanks,

    Rajan

    ReplyDelete
  5. Thank you for sharing wonderful information with us to get some idea about that content.
    ServiceNow Training in Hyderabad

    ReplyDelete

  6. I like your post very much. It is very much useful for my research. I hope you to share more info about this. Keep posting!! Best Devops Training Institute

    ReplyDelete
  7. I am Here to Get Learn Good Stuff About servicenow,Thanks For servicenow.servicenow training in bangalore

    ReplyDelete
  8. Hi Kamlesh,

    I need to do almost exactly what you wrote. The only difference is that my BIOS field is not in the cmdb_ci_computer table. Any idea how I can do this?

    ReplyDelete
  9. Very nice article,keep sharing more posts with us.
    thank you...

    Servicenow course

    ReplyDelete
  10. excellent , could you provide any video

    ReplyDelete
  11. Thank you for sharing wonderful information with us to get some idea about that content.
    ServiceNow Online Training in Hyderabad
    ServiceNow Developer Training

    ReplyDelete
  12. This is very helpful..

    ReplyDelete

Post a Comment

Popular posts from this blog

Discovery Probes and Sensors

The Year changer - YYYY