Code Snippet: XML Parse CPQLOCFG Logfile

I’m really not quite sure why HP persist in creating their own standards when it comes to data output – in this case XML. The logfile from CPQLOCFG.EXE is not valid XML, and requires a bit of mangling (much like it’s perl counterpart, locfg.pl).

Having a valid output is important to me, as many of the scripts I write generate reports or run additional commands conditional on the output response.

Having discovered that the current version of ActivePerl no longer has a port of IO::Socket:SSL, I have made to decision to move away from using the perl script for iLO interrogation in all my existing scripts. I have started down this path with the Config Wrapper Script. ThisΒ  meant that I had to come up with a way to parse the output so I can drop in to existing code.

I found in surprisingly easy. Code after the break

What I felt was going to be the hardest bit was to remove the non-XML lines from the log. Until I found out about the -notmatch operator. After that, a cleanup of an errant tag and whitespace and the XML was good to go.

$file = "D:\Powershell\mylog.txt"
[string]$logfile = (Get-Content $file) -notmatch "CPQLOCFG" -notmatch "IP Address" -notmatch "

$logfile = "", $logfile, ""
$logfile = $logfile.Replace('"/>','">')
[xml]$xml = $logfile.Trim()
foreach ($element in $xml.SelectNodes("//RIBCL")) {
if ($element.CERTIFICATE_SIGNING_REQUEST) {
$element.CERTIFICATE_SIGNING_REQUEST
}
if ($element.INFORM) {
$element.INFORM
}
$element.RESPONSE.STATUS
$element.RESPONSE.MESSAGE
}

This script outputs a CSR (if one exists), information notices (if existing) and Status/Message responses from the iLO for each instruction run.

Hopefully people will find this useful πŸ™‚

Advertisements

3 thoughts on “Code Snippet: XML Parse CPQLOCFG Logfile

    1. Ben Post author

      I’m not quite sure what you are asking here. My understanding is you are seeking the log file output of an authentication request?

      If so, then the output of the logfile is rather boring. and looks a bit like this:

      The idea of the code snippet is to return the RESPONSE and MESSAGE tags back to the script to do further actions based on the values.

      If this is not what you are asking, just reply and I’ll see what else I can come up with πŸ™‚

Comments are closed.