Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All PRTG - Output Function #3

Open
vMarkusK opened this issue Nov 8, 2016 · 2 comments
Open

All PRTG - Output Function #3

vMarkusK opened this issue Nov 8, 2016 · 2 comments

Comments

@vMarkusK
Copy link
Owner

vMarkusK commented Nov 8, 2016

Create a function to create XML Output for PRTG.

@vMarkusK vMarkusK added this to possible To Do in PRTG-VeeamBRStats via automation Oct 30, 2017
@Thyranix
Copy link

You could use something like this:

Function Write-XmlToScreen ([xml]$XML)
{
    $StringWriter = New-Object System.IO.StringWriter;
    $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter;
    $XmlWriter.Formatting = "indented";
    $xml.WriteTo($XmlWriter);
    $XmlWriter.Flush();
    $StringWriter.Flush();
    Write-Output $StringWriter.ToString();
}

Using this you can just build your XML like this:

$XML = "<prtg>"
$XML += "<result><channel>Channel1</channel><value>1</value></result>"
$XML += "</prtg>"

Running the function against $XML will return properly formatted XML data:

Write-XmlToScreen $XML

Output:

<prtg>
  <result>
    <channel>Channel1</channel>
    <value>1</value>
  </result>
</prtg>

As you can imagine you can just add to $XML throughout the script and send it all to PRTG at the end.

@vMarkusK
Copy link
Owner Author

That's a very good start. But I thought of a function that has an array or special object as input and then the PRTG compliant XML is created as a return.

@Gyslainh Gyslainh mentioned this issue Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PRTG-VeeamBRStats
  
Possible To Do
Development

No branches or pull requests

2 participants