Discovery sensor gives "TypeError: Cannot convert null to an object."

Ankush13
Kilo Guru

I have a discovery probe that returns an object(below)

Log Object: test

Object

unk_81: null = null

unk_82: null = null

unk_109: null = null

unk_84: null = null

unk_20: null = null

unk_21: null = null

unk_22: null = null

unk_23: null = null

unk_89: null = null

unk_25: null = null

unk_26: null = null

unk_27: null = null

unk_28: null = null

unk_29: null = null

unk_24: null = null

unk_88: null = null

@instance: string =

unk_87: null = null

unk_86: null = null

unk_85: null = null

unk_83: null = null

unk_111: null = null

unk_112: null = null

unk_113: null = null

unk_114: null = null

unk_110: null = null

unk_115: null = null

unk_117: null = null

unk_118: null = null

unk_119: null = null

unk_90: null = null

unk_91: null = null

unk_92: null = null

unk_93: null = null

unk_94: null = null

unk_30: null = null

unk_31: null = null

unk_32: null = null

unk_33: null = null

unk_34: null = null

unk_1: string = FOC1810U0WF

unk_2: string = FOC1810U0WF

unk_3: null = null

unk_4: null = null

unk_5: null = null

unk_6: null = null

unk_7: null = null

unk_8: null = null

unk_9: null = null

unk_99: null = null

unk_98: null = null

unk_97: null = null

unk_96: null = null

unk_95: null = null

unk_39: null = null

unk_38: null = null

unk_37: null = null

unk_36: null = null

unk_35: null = null

unk_122: null = null

unk_123: null = null

unk_124: null = null

unk_125: null = null

unk_120: null = null

unk_121: null = null

unk_126: null = null

unk_40: null = null

unk_41: null = null

unk_42: null = null

unk_43: null = null

unk_44: null = null

unk_45: null = null

unk_46: null = null

unk_47: null = null

unk_48: null = null

unk_49: null = null

unk_127: null = null

unk_128: null = null

unk_129: null = null

unk_116: null = null

unk_50: null = null

unk_51: null = null

unk_52: null = null

unk_53: null = null

unk_54: null = null

unk_55: null = null

unk_56: null = null

unk_57: null = null

unk_58: null = null

unk_59: null = null

unk_60: null = null

unk_61: null = null

unk_62: null = null

unk_63: null = null

unk_64: null = null

unk_65: null = null

unk_66: null = null

unk_67: null = null

unk_68: null = null

unk_69: null = null

unk_70: null = null

unk_71: null = null

unk_72: null = null

unk_73: null = null

unk_74: null = null

unk_10: null = null

unk_11: null = null

unk_12: null = null

unk_13: string = LIT18020YLA

unk_14: string = DCB1803G1YV

unk_15: null = null

unk_16: null = null

unk_17: null = null

unk_18: string = FOC1810U0WC

unk_19: null = null

unk_77: string = LIT18020YHZ

unk_76: null = null

unk_79: null = null

unk_78: string = DCB1803G1YM

unk_75: null = null

unk_100: null = null

unk_101: null = null

unk_102: null = null

unk_103: null = null

unk_104: null = null

unk_105: null = null

unk_106: null = null

unk_107: null = null

unk_108: null = null

unk_80: null = null

---

I wrote this script to parse it:

new DiscoverySensor( {

  process: function(result, ciData) {

  var snmp = new SNMPResponse(result);

  var moduleSwitchTable = 'iso.org.dod.internet.mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable';

  var moduleTable = snmp.getOIDTable(moduleSwitchTable, 'entPhysicalSerialNum');

  //var dlogger = new DiscoveryLogger(current.sys_id);

  //dlogger.info('Discovery started', 'Discovery');

  //var moduleList = [];

  JSUtil.logObject(moduleTable,'test');

  //gs.log('1');

  for (var module in moduleTable) {

  //gs.log('2');

  if (moduleTable[module].entPhysicalSerialNum == null) {

  continue;

  }

  //gs.log('3');

  gs.log('Serial number - ' + moduleTable[module].entPhysicalSerialNum,'Manual');

  //gs.log('4');

  }

  },

  type: 'DiscoverySensor'

});

---

It throws below error:

JavaScript evaluation error on:

new DiscoverySensor( {

process: function(result, ciData) {

var snmp = new SNMPResponse(result);

var moduleSwitchTable = 'iso.org.dod.internet.mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable';

var moduleTable = snmp.getOIDTable(moduleSwitchTable, 'entPhysicalSerialNum');

//var dlogger = new DiscoveryLogger(current.sys_id);

//dlogger.info('Discovery started', 'Discovery');

//var moduleList = [];

JSUtil.logObject(moduleTable,'test');

//gs.log('1');

for (var module in moduleTable) {

//gs.log('2');

if (moduleTable[module].entPhysicalSerialNum == null) {

continue;

}

//gs.log('3');

gs.log('Serial number - ' + moduleTable[module].entPhysicalSerialNum,'Manual');

//gs.log('4');

}

},

type: 'DiscoverySensor'

});

: org.mozilla.javascript.JavaScriptException: TypeError: Cannot convert null to an object.: org.mozilla.javascript.gen.c367346.call(sys_script_include.778011130a0a0b2500c4595ad1d1d768:29)

org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1227)

org.mozilla.javascript.BaseFunction.applyOrCall(BaseFunction.java:490)

org.mozilla.javascript.BaseFunction.execMethod(BaseFunction.java:195)

org.mozilla.javascript.IdFunction.call(IdFunction.java:78)

org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1227)

org.mozilla.javascript.gen.c168.call(sys_script_include.d22e7bdbc0a8016500a18e024bfc9aa3:4)

org.mozilla.javascript.BaseFunction.construct(BaseFunction.java:236)

org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:1329)

org.mozilla.javascript.gen.c446646.call(discovery_sensor.b958dde23730dec0ead0d5c543990ea7:1)

org.mozilla.javascript.gen.c446646.exec(discovery_sensor.b958dde23730dec0ead0d5c543990ea7)

com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:233)

com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:105)

com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:72)

com.snc.discovery.DiscoveryUtils.evaluateStringWithCurrent(DiscoveryUtils.java:91)

com.snc.discovery.sensor.processor.JavascriptSensor.process(JavascriptSensor.java:54)

com.snc.discovery.sensor.ASensor.processSensor(ASensor.java:77)

com.snc.discovery.sensor.ASensor.run(ASensor.java:71)

com.snc.discovery.SensorEvaluator.run(SensorEvaluator.java:37)

com.snc.discovery.SensorProcessor.processSensor(SensorProcessor.java:222)

com.snc.discovery.SensorProcessor.processSensors(SensorProcessor.java:173)

com.snc.discovery.SensorProcessor.process(SensorProcessor.java:122)

sun.reflect.GeneratedMethodAccessor1110.invoke(Unknown Source)

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

java.lang.reflect.Method.invoke(Method.java:597)

org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:255)

org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1227)

org.mozilla.javascript.gen.c3530.call(sys_trigger.4dad5e2b37030200ead0d5c543990edd:5)

org.mozilla.javascript.gen.c3530.exec(sys_trigger.4dad5e2b37030200ead0d5c543990edd)

com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:233)

com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:105)

com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:72)

com.glide.script.Evaluator.evaluatePossiblePrefixedString(Evaluator.java:192)

com.glide.job.RunScriptJob.evaluateScript(RunScriptJob.java:158)

com.glide.job.RunScriptJob.runScript(RunScriptJob.java:121)

com.glide.job.RunScriptJob.execute(RunScriptJob.java:88)

com.glide.schedule.JobExecutor.execute(JobExecutor.java:79)

com.glide.schedule.GlideScheduleWorker.executeJob(GlideScheduleWorker.java:177)

com.glide.schedule.GlideScheduleWorker.process(GlideScheduleWorker.java:124)

com.glide.schedule.GlideScheduleWorker.run(GlideScheduleWorker.java:56)

How can I fix this? Please advise.

6 REPLIES 6

Ankush13
Kilo Guru

tim.broberg doug.schulze Please help!


tim_broberg
ServiceNow Employee
ServiceNow Employee

Sorry, no easy answers for you.



What puzzles me here is that you're seeing a java stack dump rather than a javascript one. Where did you get this from? Is there one in the discovery log / ecc queue that has a javascript error in it with the line #?



I would start sprinkling the code with gs.log()'s and JSUtil.logObject()'s to track down where it's getting into trouble. The obvious first question to settle is whether it executes the sensor at all.


In ecc queue, it gives "TypeError: Cannot convert null to an object" under 'Error string' text box. I am currently testing using test probe option and logging the errors.


Line number is not shown which is why I have used gs.log(<num>) at 4 different places. When I run the probe, it logs 1 and 2 but doesn't log 3 and 4. It runs the sensor as it logs these under 'Script log statements'.



Under System log > Errors, I see two errors (with source as 'com.glide.ui.ServletErrorListener') :



---



Root cause of JavaScriptException: org.mozilla.javascript.NativeError
JavaScript evaluation error on:
new DiscoverySensor( {
process: function(result, ciData) {
  var snmp = new SNMPResponse(result);
  var moduleSwitchTable = 'iso.org.dod.internet.mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable';
  var moduleTable = snmp.getOIDTable(moduleSwitchTable, 'entPhysicalSerialNum');
  //var dlogger = new DiscoveryLogger(current.sys_id);
  //dlogger.info('Discovery started', 'Discovery');
  //var moduleList = [];
  JSUtil.logObject(moduleTable,'test');
  gs.log('1');
  for (var module in moduleTable) {
  gs.log('2');
  if (moduleTable[module].entPhysicalSerialNum == null) {
  continue;
  }
  gs.log('3');
  gs.log('Serial number - ' + moduleTable[module].entPhysicalSerialNum,'Manual');
  gs.log('4');
  }
},
type: 'DiscoverySensor'
});
: no thrown error


---



JavaScript evaluation error on:
new DiscoverySensor( {
process: function(result, ciData) {
  var snmp = new SNMPResponse(result);
  var moduleSwitchTable = 'iso.org.dod.internet.mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable';
  var moduleTable = snmp.getOIDTable(moduleSwitchTable, 'entPhysicalSerialNum');
  //var dlogger = new DiscoveryLogger(current.sys_id);
  //dlogger.info('Discovery started', 'Discovery');
  //var moduleList = [];
  JSUtil.logObject(moduleTable,'test');
  gs.log('1');
  for (var module in moduleTable) {
  gs.log('2');
  if (moduleTable[module].entPhysicalSerialNum == null) {
  continue;
  }
  gs.log('3');
  gs.log('Serial number - ' + moduleTable[module].entPhysicalSerialNum,'Manual');
  gs.log('4');
  }
},
type: 'DiscoverySensor'
});
: org.mozilla.javascript.JavaScriptException: TypeError: Cannot convert null to an object.: org.mozilla.javascript.gen.c367346.call(sys_script_include.778011130a0a0b2500c4595ad1d1d768:29)
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1227)
org.mozilla.javascript.BaseFunction.applyOrCall(BaseFunction.java:490)
org.mozilla.javascript.BaseFunction.execMethod(BaseFunction.java:195)
org.mozilla.javascript.IdFunction.call(IdFunction.java:78)
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1227)
org.mozilla.javascript.gen.c168.call(sys_script_include.d22e7bdbc0a8016500a18e024bfc9aa3:4)
org.mozilla.javascript.BaseFunction.construct(BaseFunction.java:236)
org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:1329)
org.mozilla.javascript.gen.c457321.call(discovery_sensor.b958dde23730dec0ead0d5c543990ea7:1)
org.mozilla.javascript.gen.c457321.exec(discovery_sensor.b958dde23730dec0ead0d5c543990ea7)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:233)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:105)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:72)
com.snc.discovery.DiscoveryUtils.evaluateStringWithCurrent(DiscoveryUtils.java:91)
com.snc.discovery.sensor.processor.JavascriptSensor.process(JavascriptSensor.java:54)
com.snc.discovery.sensor.ASensor.processSensor(ASensor.java:77)
com.snc.discovery.sensor.ASensor.run(ASensor.java:71)
com.snc.discovery.SensorEvaluator.run(SensorEvaluator.java:37)
com.snc.discovery.SensorProcessor.processSensor(SensorProcessor.java:222)
com.snc.discovery.SensorProcessor.processSensors(SensorProcessor.java:173)
com.snc.discovery.SensorProcessor.process(SensorProcessor.java:122)
sun.reflect.GeneratedMethodAccessor1110.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:255)
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1227)
org.mozilla.javascript.gen.c3530.call(sys_trigger.4dad5e2b37030200ead0d5c543990edd:5)
org.mozilla.javascript.gen.c3530.exec(sys_trigger.4dad5e2b37030200ead0d5c543990edd)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:233)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:105)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:72)
com.glide.script.Evaluator.evaluatePossiblePrefixedString(Evaluator.java:192)
com.glide.job.RunScriptJob.evaluateScript(RunScriptJob.java:158)
com.glide.job.RunScriptJob.runScript(RunScriptJob.java:121)
com.glide.job.RunScriptJob.execute(RunScriptJob.java:88)
com.glide.schedule.JobExecutor.execute(JobExecutor.java:79)
com.glide.schedule.GlideScheduleWorker.executeJob(GlideScheduleWorker.java:177)
com.glide.schedule.GlideScheduleWorker.process(GlideScheduleWorker.java:124)
com.glide.schedule.GlideScheduleWorker.run(GlideScheduleWorker.java:56)



Ankush13
Kilo Guru

Please help guys...