#!/usr/bin/perl # Copyright (c) 2000-2002 Carnegie Mellon University. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. The name "Carnegie Mellon University" must not be used to endorse or # promote products derived from this software without prior written # permission. For permission or any legal details, please contact: # Office of Technology Transfer # Carnegie Mellon University # 5000 Forbes Avenue # Pittsburgh, PA 15213-3890 # (412) 268-4387, fax: (412) 268-7395 # tech-transfer@andrew.cmu.edu # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: "This product includes software developed by Computing # Services at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS # SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, # IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, # INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. use DBIWrapper; my $db = DBIWrapper->new(dbType => "mysql", dbName => "netsage", dbHost => "localhost", dbUser => "netsage-maint", dbPasswd => `cat /home/netsage/etc/.password-maint`, printError => 1, raiseError => 1); if ($db->didErrorOccur()) { die $db->errorMessage(); } $out = ""; foreach $i (qw(hosts hostgroups hostgroup_memberships server_types servers server_files attribute_types actions service_class service_types services subperiods alert_period attributes dependency_tree users usergroups usergroup_memberships)) { $tempxml .= $db->readXML(sql=> "select * from $i order by id"); } $db->close(); @lines = split /\n/, $tempxml; $decl = shift @lines; if ($decl !~ /^<\?xml/) { die "No xml declaration at top of query results\n"; } print $decl; print "\n\n"; while ($_ = shift @lines) { next if (/^<\?xml/); if (//>/g); $status =~ (s/\"/"/g); $status =~ (s/\//&slash;/g); $select =~ (s//>/g); $select =~ (s/\"/"/g); $select =~ (s/\//&slash;/g); if ($status !~ /<status result="Ok" error=""&slash;>/) { die "The input contains the results of a failed query\n"; } if ($select =~ /<select sql="select \* from (\w+) order by id"/) { $table=$1; } else { die "The input contains the results of a complex query I can't parse\n"; } print "\n"; next; } print $_ . "\n"; } print "\n";