The community will be in read-only from Tuesday 11:59pm (PST) to Wednesday noon (PST)
The community will be in read-only from Tuesday 11:59pm (PST) to Wednesday noon (PST)
UCMDB and UD Practitioners Forum (Previously CMS)
cancel
Showing results for 
Search instead for 
Did you mean: 

HP uCMDB : Need help with ObjectStateHolder Syntax for a custom Jython script

Highlighted
Praveen_Shan
Collector

HP uCMDB : Need help with ObjectStateHolder Syntax for a custom Jython script

Hello experts,

 

I have a discovery script that determines custom attribute values using external resources and updates the CMDB.

One such attribute is of data type, string_list. I'd like to know what the syntax is, for sending the results as a string list and not as a string. Page 48 on UCMDB9.05_DevelopersRef.pdf didn't give me the answer I was looking for.

 

Error thrown when result is sent as;
1: hostOSH.setAttributeToList('custom_host_test_6',"")

2: hostOSH.setString_listAttribute('custom_host_test_6',"")

3: hostOSH.setStringAttributeAsList('custom_host_test_6',"")

<< Progress message, Severity: Error>>
Failed executing script, details: Traceback (innermost last):
  File "<string>", line 2, in ?
  File "XYZ_NodeAttributes_Network", line 82, in DiscoveryMain
AttributeError: setAttributeToList

 

When I use String, it obviously doesn't work either.
hostOSH.setStringAttribute('custom_host_test_6',"")
<< Progress message, Severity: Error>>
Error processing results of discovery adapter, details Attribute custom_host_test_6 of object <?xml version="1.0" encoding="UTF-8"?><object id="47748b831aa231c8c424024d327585c3" id_type="CmdbObjectID" class="wireless_ap" isReference="false" anchor_id="null" is_anchor="false"><attribute name="custom_host_test_3" type="String"></attribute><attribute name="custom_host_test_2" type="String"></attribute><attribute name="custom_host_test_1" type="String"></attribute><attribute name="custom_host_test_6" type="String"></attribute><attribute name="custom_host_test_5" type="String"></attribute><attribute name="custom_host_test_4" type="String"></attribute></object> of wrong type;should be string_list but reported String
    at com.hp.ucmdb.discovery.library.results.resultprocess.ResultProcessDataValidator.checkAttributeType(ResultProcessDataValidator.java:300)
    at com.hp.ucmdb.discovery.library.results.resultprocess.ResultProcessDataValidator.checkAttributes(ResultProcessDataValidator.java:198)
    at com.hp.ucmdb.discovery.library.results.resultprocess.ResultProcessDataValidator.filterInvalidObjects(ResultProcessDataValidator.java:116)
    at com.hp.ucmdb.discovery.library.results.resultprocess.ResultProcessDataValidator.doProcess(ResultProcessDataValidator.java:87)
    at com.hp.ucmdb.discovery.library.results.resultprocess.ResultProcess.process(ResultProcess.java:15)
    at com.hp.ucmdb.discovery.library.results.resultprocess.ResultProcessChain.doProcess(ResultProcessChain.java:60)
    at com.hp.ucmdb.discovery.probe.agents.probemgr.discoveryscheduler.ResultSenderImpl.processResult(ResultSenderImpl.java:148)
    at com.hp.ucmdb.discovery.probe.agents.probemgr.discoveryscheduler.ResultSenderImpl.processResults(ResultSenderImpl.java:98)
    at com.hp.ucmdb.discovery.probe.services.dynamic.core.DynamicService.discover(DynamicService.java:77)
    at com.hp.ucmdb.discovery.probe.agents.probemgr.taskexecuter.JobExecuter.launchTask(JobExecuter.java:1238)
    at com.hp.ucmdb.discovery.probe.agents.probemgr.taskexecuter.JobExecuter$JobExecuterWorker.launch(JobExecuter.java:993)
    at com.hp.ucmdb.discovery.probe.agents.probemgr.taskexecuter.JobExecuter$JobExecuterWorker.executeTask(JobExecuter.java:930)
    at com.hp.ucmdb.discovery.probe.agents.probemgr.taskexecuter.JobExecuter$JobExecuterWorker.run(JobExecuter.java:836)
    
This is the piece of code I'm working on. The first few attributes are of data type, string and they work fine.
# To Clear out all the test Attributes Set Clear_Out to Y
    Clear_Out = "Y"
    if Clear_Out == "Y":
       hostOSH.setAttribute('custom_host_test_1',"")
       hostOSH.setAttribute('custom_host_test_2',"")
       hostOSH.setAttribute('custom_host_test_3',"")
       hostOSH.setAttribute('custom_host_test_4',"")
       hostOSH.setAttribute('custom_host_test_5',"")     
       hostOSH.setStringAttribute('custom_host_test_6',"")
       logger.info("All Test Attributes Cleared")     
       OSHVResult.add(hostOSH)
       return OSHVResult


Please see attached screenshot.

 

Thanks,

Praveen

1 REPLY
Praveen_Shan
Collector

Re: HP uCMDB : Need help with ObjectStateHolder Syntax for a custom Jython script

I figured a couple ways to do it:

The easiest is probably to create a list of the values in a list variable, then use the OSH method setListAttribute(name, list_of_values)
Please note that when using setListAttribute, the existing list values will be blown away, i.e. the list you build will replace the old list, not add to it.

Another way would be to also use AttributeStateHolder objects,. AttributeStateHolder is more flexible, but more baggage then generally needed.

 

Thanks,

Praveen

//Add this to "OnDomLoad" event