From: Robert 'phaylon' Sedlacek Date: Thu, 24 May 2012 02:42:01 +0000 (+0000) Subject: inttrospector cli X-Git-Tag: v0.001_001~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b549a66352690a36492b43f6fa851f8e44885ae6;hp=60e1cc39c0dc98165bdeb13c0f522ac18ebb5153;p=scpubgit%2FSystem-Introspector.git inttrospector cli --- diff --git a/bin/system-introspector b/bin/system-introspector new file mode 100644 index 0000000..0c16443 --- /dev/null +++ b/bin/system-introspector @@ -0,0 +1,86 @@ +#!/usr/bin/env perl +use strictures 1; + +use Getopt::Long; +use Pod::Usage; +use System::Introspector::State; +use File::Tree::Snapshot; +use System::Introspector::Config; + +GetOptions( + 'c|config=s' => \my $config_file, + 's|storage=s' => \my $storage_dir, + 'H|host=s' => \my $hostname, + 'allow-empty' => \my $allow_empty, + 'a|all' => \my $update_all, + 'g|group=s' => \my @update_groups, + 'h|help' => sub { pod2usage(0) }, +) or pod2usage(2); + +die "Requires --all or --group option\n" + unless $update_all or @update_groups; + +my $config = System::Introspector::Config->new( + config_file => (defined($config_file) + ? $config_file + : "$storage_dir/main.conf"), +); + +$config->has_group($_) or die "Unknown group '$_'\n" + for @update_groups; + +@update_groups = $config->groups + if $update_all; + +for my $group (@update_groups) { + my $group_dir = "$storage_dir/$group"; + print "Group $group at $group_dir\n"; + my $storage = File::Tree::Snapshot->new( + storage_path => $group_dir, + allow_empty => $allow_empty, + ); + $storage->create + unless $storage->exists; + my $state = System::Introspector::State->new( + defined($hostname) ? (host => $hostname) : (), + storage => $storage, + config => $config->config_for_group($group), + ); + eval { $state->fetch_and_store }; + if (my $error = $@) { + $storage->reset; + } + else { + $storage->commit; + } +} + +__END__ + +=head1 NAME + +system-introspector - Generate System Introspection Data + +=head1 SYNOPSIS + + system-introspector --storage [OPTIONS] + +=head1 OPTIONS + +=head2 -s , --storage + +Path to storage. Always required. + +=head2 -H , --host + +Remote host gathering + +=head2 --allow-empty + +Allow empty commits to storage. + +=head2 -h, --help + +Display help. + +=cut