Discovery sensor - get CI sysid

Michael Skov
Tera Contributor

Hi all

 

I am created a custom probe/sensor. The input is fine, but i cannot relate the input to a CI. I am trying "g_device.getCmdbCi()" og "this.getCmdbCi()", but none of them returns anything. It seems to be the same code used in "Windows - JBoss Get jboss-service.xml" or "Windows - JBoss Find web.xml List" probes.

 

I have tried both DiscoveryJSONSensor and DiscoverySensor, but that doesnt change anything. 

 
The script im using:

 

                var gr = new GlideRecord("u_cmdb_ci_vms_package");
                gr.addQuery("name", packages.name);
                gr.query();

                if (!gr.next()) {
                    gr.initialize();
                    gr.setNewGuid();
                    gr.name = packages.name;
                    gr.description = packages.description;
                    gr.cmdb_ci =  this.getCmdbCi();
                    gr.insert();

 

 

What can the issue be?

 

Thanks!

3 REPLIES 3

amaradiswamy
Kilo Sage

Hi @Michael Skov 

 

I think this.getCmdbCi return the GlideRecord object. Can you try with below, I have also added log statement to check if this method is returning any value or not:

              var   deviceGr = this.getCmdbCi();
               gs.info('The device sys id is'+deviceGr.sys_id);
                var gr = new GlideRecord("u_cmdb_ci_vms_package");
                gr.addQuery("name", packages.name);
                gr.query();

                if (!gr.next()) {

                    gr.initialize();
                    gr.setNewGuid();
                    gr.name = packages.name;
                    gr.description = packages.description;
                    gr.cmdb_ci =  deviceGr.sys_id;
                    gr.insert();

 

Thank you for the response. I tried that too, but same result. The oob sensors are also not doing it this way.

And just to elaborate, i get the following error:

org.mozilla.javascript.JavaScriptException: TypeError: Cannot read property "sys_id" from null