0

I am trying to move our Pre-existing PRTG setup to a Nagios setup. The problem is that we currently have over 20k monitors, and so i'm trying to export the sensor information out of the .dat file and into a readable file that can be moved into a number of other nagios files. The problem is, I'm still very new to scripting and aside from creating a script that can split up the file so that bash doesn't kill itself, all attempts have failed. I tried to use a script someone else had written, but i don't think it will work for what I need it to.

I am needing to extract the following information Everything between host***/host and name***/name

If someone could at least point me in the direction where I could figure out how to write something that would allow me to extract a range of text, that would work as well. :)

Example:

<host>
10.0.0.0
</host>
<name>
This is a Business
</name>

Keep in mind this config file I am using is a .dat file that is almost a gig in size.

<?xml version="1.0" encoding="UTF-8"?>
<root version="15" oct="PRTG Network Monitor 17.2.31.1917 x64" 
saved="5/12/2017 4:36:26 PM" max="184692" guid="{3A6843F2-61BB-47EA-8EB2-
B2E62E24EF2F}" treeversion="0" created="2009-10-02-19-22-11" 
<statistics time="12-05-2017 16:09:19">
3

Use an XML parser like XMLStarlet:

$ xml sel -t -v '//host' -v '//name' file.xml

This would extract the contents of any <host> or <name> node anywhere in the file.xml XML document.

XMLStarlet is likely available through your ordinary package manager. The executable is sometimes called xmlstarlet rather than just xml.

  • Got some errors when doing this, PRTG Configuration(Copy).dat:14514917.69: PCDATA invalid Char value 24 MERAKI-CLOUD-CONTROLLER-MIB/dev: &#x0d;/d And PRTG Configuration(Copy).dat:14794305.35: xmlSAX2Characters: huge text node: out of memory – Temple Pate Jun 2 '17 at 4:34
  • If it helps.. link – Temple Pate Jun 2 '17 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.