From a3ed36842d1e4762f81d8ad9c10bd36dc73a26c3 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 9 Nov 2012 15:00:17 +0100 Subject: pingdata.xml: add new file for dynamic ping data of the clients bcfg2-ping-sweep saved the pingdata into clients.xml. This is problematic if the repository is tracked by a vcs. Now the dynamic data is saved into pingdata.xml and the DBStat plugin reads the data from there. So the pingdata.xml could be ignored by the vcs. --- src/sbin/bcfg2-ping-sweep | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2-ping-sweep b/src/sbin/bcfg2-ping-sweep index 70f718690..585e1cc11 100755 --- a/src/sbin/bcfg2-ping-sweep +++ b/src/sbin/bcfg2-ping-sweep @@ -20,6 +20,7 @@ if __name__ == '__main__': cfpath = setup['configfile'] clientdatapath = "%s/Metadata/clients.xml" % setup['repo'] + pingdatapath = "%s/Metadata/pingdata.xml" % setup['repo'] clientElement = lxml.etree.parse(clientdatapath) hostlist = [client.get('name') @@ -32,6 +33,7 @@ if __name__ == '__main__': #/bin/ping on linux /sbin/ping on os x osname = uname()[0] + container = lxml.etree.Element("PingStatistics") while hostlist or pids: if hostlist and len(list(pids.keys())) < 15: host = hostlist.pop() @@ -58,15 +60,17 @@ if __name__ == '__main__': continue chost = pids[cpid] del pids[cpid] - elm = clientElement.xpath("//Client[@name='%s']" % chost)[0] + elm = lxml.etree.Element('Client', name=chost) if status == 0: elm.set("pingable", 'Y') elm.set("pingtime", str(time.time())) else: elm.set("pingable", 'N') + container.append(elm) - fout = open(clientdatapath, 'w') - fout.write(lxml.etree.tostring(clientElement.getroot(), + fout = open(pingdatapath, 'w') + fout.write(lxml.etree.tostring(container, encoding='UTF-8', - xml_declaration=True)) + xml_declaration=True, + pretty_print=True)) fout.close() -- cgit v1.2.3-1-g7c22