Highlighted
Trusted Contributor.
Trusted Contributor.
806 views

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.

Tags (1)
0 Likes
4 Replies
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: uCMDB discovery from Json file

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

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

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

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

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

0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: uCMDB discovery from Json file

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)

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.