Commit | Line | Data |
b549a663 |
1 | #!/usr/bin/env perl |
2 | use strictures 1; |
3 | |
4 | use Getopt::Long; |
5 | use Pod::Usage; |
6 | use System::Introspector::State; |
7 | use File::Tree::Snapshot; |
8 | use System::Introspector::Config; |
9 | |
10 | GetOptions( |
11 | 'c|config=s' => \my $config_file, |
12 | 's|storage=s' => \my $storage_dir, |
13 | 'H|host=s' => \my $hostname, |
14 | 'allow-empty' => \my $allow_empty, |
15 | 'a|all' => \my $update_all, |
16 | 'g|group=s' => \my @update_groups, |
17 | 'h|help' => sub { pod2usage(0) }, |
18 | ) or pod2usage(2); |
19 | |
20 | die "Requires --all or --group option\n" |
21 | unless $update_all or @update_groups; |
22 | |
23 | my $config = System::Introspector::Config->new( |
24 | config_file => (defined($config_file) |
25 | ? $config_file |
26 | : "$storage_dir/main.conf"), |
27 | ); |
28 | |
29 | $config->has_group($_) or die "Unknown group '$_'\n" |
30 | for @update_groups; |
31 | |
32 | @update_groups = $config->groups |
33 | if $update_all; |
34 | |
35 | for my $group (@update_groups) { |
36 | my $group_dir = "$storage_dir/$group"; |
37 | print "Group $group at $group_dir\n"; |
38 | my $storage = File::Tree::Snapshot->new( |
39 | storage_path => $group_dir, |
40 | allow_empty => $allow_empty, |
41 | ); |
42 | $storage->create |
43 | unless $storage->exists; |
44 | my $state = System::Introspector::State->new( |
45 | defined($hostname) ? (host => $hostname) : (), |
46 | storage => $storage, |
47 | config => $config->config_for_group($group), |
48 | ); |
49 | eval { $state->fetch_and_store }; |
50 | if (my $error = $@) { |
51 | $storage->reset; |
52 | } |
53 | else { |
54 | $storage->commit; |
55 | } |
56 | } |
57 | |
58 | __END__ |
59 | |
60 | =head1 NAME |
61 | |
62 | system-introspector - Generate System Introspection Data |
63 | |
64 | =head1 SYNOPSIS |
65 | |
66 | system-introspector --storage <path> [OPTIONS] |
67 | |
68 | =head1 OPTIONS |
69 | |
70 | =head2 -s <path>, --storage <path> |
71 | |
72 | Path to storage. Always required. |
73 | |
74 | =head2 -H <host>, --host <host> |
75 | |
76 | Remote host gathering |
77 | |
78 | =head2 --allow-empty |
79 | |
80 | Allow empty commits to storage. |
81 | |
82 | =head2 -h, --help |
83 | |
84 | Display help. |
85 | |
86 | =cut |