in reply to Re^2: Need help with complex hash of hashes.
in thread Need help with complex hash of hashes.
Does the first row returned contain a set of empty tags and subsequent rows contain the same tags with data? Something like:
<result> <checked_in></checked_in> <change_request></change_request> <po_number></po_number> </result> <result> <checked_in>yesterday</checked_in> <change_request>AQX123</change_request> <po_number>42</po_number> </result>
Until, of course, you get to:
<result> <po_number>42</po_number> <checked_in>1 week ago</checked_in> <change_request>AQX120</change_request> </result>
And your parsing by position produces bogus results.
Or is it really XML-encoded CSV? More like:
<result> <checked_in></checked_in> <change_request></change_request> <po_number></po_number> </result> <result> <bogon>yesterday</bogon> <bogon>AQX123</bogon> <bogon>42</bogon> </result>
In the former case, you don't need the positions after all, and the fact that they change from run to run should indicate that they are not significant. In the latter case, your CMDB belongs on the Daily WTF. Your code mentions an option for JSON output. Perhaps that module is less broken?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Need help with complex hash of hashes.
by vlturner (Sexton) on Jan 28, 2016 at 15:26 UTC | |
So there are 250K CI records. You have CI's for devices with their IP addresses where 'name' is the hostname and a referral CI ( 'u_application_id' )to the application they are children of, and you have CI's that are the application, where 'name' is the application name. You have no control of the order of the records. If the class name 'sys_class_name' is equal to 'cmdb_ci_appl' then it is an application name. If not then it is probably a device and if its 'u_application_id' CI matches and application CI 'u_ci_id' then its 'ip_address' is a member of that application. Now all lines have a CI 'u_ci_id' something like CI10001127. I hope this helps. We are trying to end up with a hash that looks like this.
But are ending up with this.
With no members.....
| [reply] [d/l] [select] |
by jcb (Parson) on Jan 29, 2016 at 04:05 UTC | |
After parsing the XML into something sane (see my previous comment), the next step is to build the hash you want:
This code has minimal consistency checks. Making it fully robust is left as an exercise for the reader. | [reply] [d/l] |
|
Re^4: Need help with complex hash of hashes.
by vlturner (Sexton) on Jan 28, 2016 at 15:55 UTC | |
Here is an XML record
| [reply] [d/l] |
by poj (Abbot) on Jan 28, 2016 at 17:43 UTC | |
If you run this against your XML it will filter out the relevant tags
Result poj | [reply] [d/l] [select] |
by vlturner (Sexton) on Jan 28, 2016 at 18:56 UTC | |
Shouldn't this.
Be this
I got this error.
| [reply] [d/l] [select] |
by poj (Abbot) on Jan 28, 2016 at 19:33 UTC | |
by vlturner (Sexton) on Jan 28, 2016 at 21:22 UTC | |
by poj (Abbot) on Jan 28, 2016 at 19:31 UTC | |
| [reply] |
by jcb (Parson) on Jan 29, 2016 at 03:52 UTC | |
So here is some sample code that parses this into a hash with the sample XML embedded in the script at the __DATA__ marker:
This puts the entries into a hash and then dumps the hash to show that parsing works. I'll elaborate further in the other subthread. | [reply] [d/l] |