inttrospector cli
Robert 'phaylon' Sedlacek [Thu, 24 May 2012 02:42:01 +0000 (02:42 +0000)]
bin/system-introspector [new file with mode: 0644]

diff --git a/bin/system-introspector b/bin/system-introspector
new file mode 100644 (file)
index 0000000..0c16443
--- /dev/null
@@ -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 <path> [OPTIONS]
+
+=head1 OPTIONS
+
+=head2 -s <path>, --storage <path>
+
+Path to storage. Always required.
+
+=head2 -H <host>, --host <host>
+
+Remote host gathering
+
+=head2 --allow-empty
+
+Allow empty commits to storage.
+
+=head2 -h, --help
+
+Display help.
+
+=cut