From: Pat O'B. <obr...@gm...> - 2011-07-30 03:55:01
|
Well, I got something working, but it's fairly ugly (don't you hate it when you find a solution a few minutes AFTER you send an email to a mailing list?). First, I finally found the tag in XML to have it ignore XML "like" markup: <![CDATA[ <who wants icecream?> ]]> This solved the problem of etch bailing when loading up the XML file into the @local_requests variable, but wouldn't solve REXML bailing. What I did to fix that is somewhat jankey: if @local_requests && !@local_requests.empty? require 'rexml/document' this_is_pretty_ugly = REXML::Document.new() requests_xml = REXML::Document.new(@local_requests) requests_xml.elements.each('/requests/request') do |request_xml| request_xml.to_s.split("\n").each do |line| next if line =~ /^\]\]\>|^\!\[CDATA\[|^\<request\>|^\<\/request\>/ @contents << line + "\n" end end end Normally I would have offended myself with this sort of solution, but since we're writing a chef resource to add the contents to the local request file we should be able to control it well enough without having to worry about someone placing in bad XML or XML like languages into the file for etch to pick up. It would be nice if there didn't need to be a work around, although I completely understand why the behavior is the way it is. Anyway, hope this helps anyone who tries and gets caught with this. -pat On Fri, Jul 29, 2011 at 8:33 PM, Pat O'Brien <obr...@gm...>wrote: > collectd appears to have it's config file set up to read "quasi-xml", which > is causing etch to fail when parsing it for a local request: > > Local request file > /var/etch/requests/data/svc/collectd/etc/collectd.conf/from_etch is not > valid XML and will be ignored: > #<REXML::ParseException: malformed XML: missing tag start > Line: > Position: > Last 80 unconsumed characters: > <Plugin "tail"> <File "/data/svc/mule/instance01/logs/log4j.log"> > Instance > > ... > > here is what the config bit looks like: > > <Plugin "tail"> > <File "/data/svc/app/logs/log4j.log"> > Instance "westcoast" > <Match> > Regex "ERROR" > DSType "CounterInc" > Type "derive" > Instance "instance_errors" > </Match> > </File> > </Plugin> > > Running this through other XML verifiers also verifies that this is not > valid XML. One problem I noticed is that any invalid XML (or XML like file, > including HTML and ERB included) in the local requests directory will cause > etch to bail when slurping in to add the contents to @local_requests. > > Initially I thought it was just REXML bailing on loading the local request > and rejecting it, but it looks like it is etch itself which is bailing > (although it's completely possible that REXML would bail in the script > itself as well since REXML validates XML when it loads it). > > Any thoughts on where to go from here? Is there an XML tag that allows free > form text and ignores all formatting of data within the tag end and the tag > begin? I'll also dig through collectd and see if I can make the config > proper XML as well. > > -pat > |