#!/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, 'U|user=s' => \my $username, '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; die "The --user option also requires a --host to be set\n" if defined($username) and not defined($hostname); 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; my $sudo_user = $config->sudo_user; 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) : (), defined($username) ? (user => $username) : (), defined($sudo_user) ? (sudo_user => $sudo_user) : (), storage => $storage, config => $config->config_for_group($group), ); eval { $state->fetch_and_store }; if (my $error = $@) { warn "Error: $error\n"; $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