Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created March 1, 2013 19:25
Show Gist options
  • Save waffle2k/5067080 to your computer and use it in GitHub Desktop.
Save waffle2k/5067080 to your computer and use it in GitHub Desktop.
When exporting templates from zabbix, it defaults the download name to something generic. It's useful to then rename all of the xml files to reflect their template name.
#!/usr/bin/perl -s
use XML::Simple;
my @files = grep { /\.xml$/ and -f $_ } @ARGV;
for my $filename ( @files ){
my $xml = XML::Simple->new;
my $data = $xml->XMLin( $filename );
next unless defined $data->{templates}->{template}->{name};
if( $data->{templates}->{template}->{name} eq $data->{templates}->{template}->{template} ){
print "I: rename [$filename] to [$data->{templates}->{template}->{name}.xml]\n"
unless $filename eq "$data->{templates}->{template}->{name}.xml";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment