UCMDB and UD Practitioners Forum (Previously CMS)
Showing results for 
Search instead for 
Do you mean 

uCMDB discovery from Json file

Advisor

uCMDB discovery from Json file

Hello all,

Any somoene can help me how i can solve my issue:

i want to discovery CIs from an url contains a json data, the goal is to create my Business applications from this url or file. i have put my adapter based on python script but it can't executed each time i have echec because syntaxe error.

the version of ucmdb is 9.05 on windows server.

4 REPLIES
Advisor

Re: uCMDB discovery from Json file

[ Edited ]

Please paste the error here, otherwise it's difficult to help you.
Note that 9.05 is using jython 2.3 or even older, meaning that there's no out of the box module for parsing JSON. There is a workaround however, google this: import com.xhaus.jyson.JysonCodec as json

Advisor

Re: uCMDB discovery from Json file

hello thank you for your reply

mys script is very easy:

import string
import re

import logger
import modeling
#from httplib import HTTPConnection
import httplib
from appilog.common.system.types import ObjectStateHolder
from appilog.common.system.types.vectors import ObjectStateHolderVector

##############################################
######## MAIN ##########
##############################################
def DiscoveryMain(Framework):
OSHVResult = ObjectStateHolderVector()

url='https://xxxxx/version.json'
## Write implementation to return new result CIs here...

jsonurl = urllib.urlopen(url)

data = json.loads(jsonurl.read())

logger.warn("notre url est: " + data)

return OSHVResult

 

 

the error is:

 

<< Progress message, Severity: Error>>
Échec d´exécution du script. Détails : Traceback (innermost last):
File "<string>", line 2, in ?
File "tes_url_parse", line 20, in DiscoveryMain
NameError: urllib

Advisor

Re: uCMDB discovery from Json file

Also i try with this way but i have the error bellow:

 

def DiscoveryMain(Framework):
OSHVResult = ObjectStateHolderVector()

url = Framework.getParameter('url')
## Write implementation to return new result CIs here...
#jsonurl = urllib.urlopen(url)
#data = json.loads(jsonurl.read())
#logger.warn("notre url est: " + data)
conn = HTTPConnection(url)

logger.warn("URL:" + url)
conn.request(url)
response = conn.getresponse();
if response.status >= 200 and response.status < 300:
return handle_success(response)
else:
return handle_exception(response)

return OSHVResult

 

Error

<< Progress message, Severity: Error>>
Échec d´exécution du script. Détails : Traceback (innermost last):
File "<string>", line 2, in ?
File "tes_url_parse", line 30, in DiscoveryMain
File "D:\Applis\hp\UCMDB\DataFlowProbe\bin\..\jython\Lib\httplib.py", line 342, in __init__
File "D:\Applis\hp\UCMDB\DataFlowProbe\bin\..\jython\Lib\httplib.py", line 348, in _set_hostport
ValueError: invalid literal for __int__: //xxxxxxxxxxxx/version.json

 

 

thanks for your help

Advisor

Re: uCMDB discovery from Json file

[ Edited ]

In your first post, you are not importing urllib:
NameError: urllib

try adding: import * from urllib in the first line of the script

In the second script it seems that some vital parts of the script are not visible, making it hard to deduct where the problem originates from, but the error itself suggests that the function is expecting an integer but getting a string instead. Httplib source code suggests that a port needs to be defined along with the URL:

http://bugs.python.org/file3963/httplib.diff

self._set_hostport(host, port)

 Maybe it would work like this:

conn.request(url,8080)  (or whatever the port is)

//Add this to "OnDomLoad" event