« lib/Monitoring/Generator/TestConfig/Modules/Shinken.pm
↑ Summary
lib/Monitoring/Generator/TestConfig/HostCheckData.pm »
| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | create_test_config.pl - create a test configuration | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | ./create_test_config.pl [ -h ] [ -v ] [ -b <monitoring binary> ] [ -p <prefix> ] [ -l layout ] [ <directory> ] | ||
| 10 | |||
| 11 | =head1 DESCRIPTION | ||
| 12 | |||
| 13 | this script generates a valid test configuration | ||
| 14 | |||
| 15 | =head1 ARGUMENTS | ||
| 16 | |||
| 17 | script has the following arguments | ||
| 18 | |||
| 19 | =over 4 | ||
| 20 | |||
| 21 | =item help | ||
| 22 | |||
| 23 | -h | ||
| 24 | |||
| 25 | print help and exit | ||
| 26 | |||
| 27 | =item verbose | ||
| 28 | |||
| 29 | -v | ||
| 30 | |||
| 31 | verbose output | ||
| 32 | |||
| 33 | =item prefix | ||
| 34 | |||
| 35 | -p | ||
| 36 | |||
| 37 | add this prefix to all exported hosts and services | ||
| 38 | |||
| 39 | =item binary | ||
| 40 | |||
| 41 | nagios/icinga binary to use | ||
| 42 | |||
| 43 | will search for nagios, nagios3 and icinga in path if not set | ||
| 44 | |||
| 45 | =item layout | ||
| 46 | |||
| 47 | use nagios or icinga | ||
| 48 | |||
| 49 | =item directory | ||
| 50 | |||
| 51 | output directory for export | ||
| 52 | |||
| 53 | =back | ||
| 54 | |||
| 55 | =head1 EXAMPLE | ||
| 56 | |||
| 57 | ./create_test_config.pl -p test1 /tmp/test-config/ | ||
| 58 | |||
| 59 | =head1 AUTHOR | ||
| 60 | |||
| 61 | 2009, Sven Nierlein, <nierlein@cpan.org> | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | use warnings; | ||
| 66 | use strict; | ||
| 67 | use Getopt::Long; | ||
| 68 | use Pod::Usage; | ||
| 69 | use lib '../lib'; | ||
| 70 | use lib 'lib'; | ||
| 71 | use Monitoring::Generator::TestConfig; | ||
| 72 | |||
| 73 | ######################################################################### | ||
| 74 | # parse and check cmd line arguments | ||
| 75 | my ($opt_h, $opt_v, $opt_p, $opt_b, $opt_d, $opt_l); | ||
| 76 | Getopt::Long::Configure('no_ignore_case'); | ||
| 77 | if(!GetOptions ( | ||
| 78 | "h" => \$opt_h, | ||
| 79 | "v" => \$opt_v, | ||
| 80 | "p=s" => \$opt_p, | ||
| 81 | "b=s" => \$opt_b, | ||
| 82 | "l=s" => \$opt_l, | ||
| 83 | "<>" => \&add_dir, | ||
| 84 | )) { | ||
| 85 | pod2usage( { -verbose => 1, -message => 'error in options' } ); | ||
| 86 | exit 3; | ||
| 87 | } | ||
| 88 | |||
| 89 | if(defined $opt_h) { | ||
| 90 | pod2usage( { -verbose => 1 } ); | ||
| 91 | exit 3; | ||
| 92 | } | ||
| 93 | my $verbose = 0; | ||
| 94 | if(defined $opt_v) { | ||
| 95 | $verbose = 1; | ||
| 96 | } | ||
| 97 | |||
| 98 | if(!defined $opt_d and !defined $ENV{'OMD_ROOT'}) { | ||
| 99 | pod2usage( { -verbose => 1, -message => 'no export directory given!' } ); | ||
| 100 | exit 3; | ||
| 101 | } | ||
| 102 | |||
| 103 | $opt_p = "" unless defined $opt_p; | ||
| 104 | $opt_l = "nagios" unless defined $opt_l or defined $ENV{'OMD_ROOT'}; | ||
| 105 | |||
| 106 | |||
| 107 | ######################################################################### | ||
| 108 | my $ngt = Monitoring::Generator::TestConfig->new( | ||
| 109 | 'output_dir' => $opt_d, | ||
| 110 | 'layout' => $opt_l, | ||
| 111 | 'verbose' => 1, | ||
| 112 | 'overwrite_dir' => 1, | ||
| 113 | 'prefix' => $opt_p, | ||
| 114 | 'binary' => $opt_b, | ||
| 115 | 'routercount' => 10, | ||
| 116 | 'hostcount' => 100, | ||
| 117 | 'services_per_host' => 10, | ||
| 118 | 'main_cfg' => { | ||
| 119 | #'broker_module' => '/opt/projects/git/check_mk/livestatus/src/livestatus.o /tmp/live.sock', | ||
| 120 | }, | ||
| 121 | 'hostfailrate' => 2, # percentage | ||
| 122 | 'servicefailrate' => 5, # percentage | ||
| 123 | 'host_settings' => { | ||
| 124 | 'normal_check_interval' => 30, | ||
| 125 | 'retry_check_interval' => 5, | ||
| 126 | }, | ||
| 127 | 'service_settings' => { | ||
| 128 | 'normal_check_interval' => 30, | ||
| 129 | 'retry_check_interval' => 5, | ||
| 130 | }, | ||
| 131 | 'router_types' => { | ||
| 132 | 'down' => 10, # percentage | ||
| 133 | 'up' => 10, | ||
| 134 | 'flap' => 10, | ||
| 135 | 'pending' => 10, | ||
| 136 | 'random' => 60, | ||
| 137 | }, | ||
| 138 | 'host_types' => { | ||
| 139 | 'down' => 5, # percentage | ||
| 140 | 'up' => 50, | ||
| 141 | 'flap' => 5, | ||
| 142 | 'pending' => 5, | ||
| 143 | 'random' => 35, | ||
| 144 | }, | ||
| 145 | 'service_types' => { | ||
| 146 | 'ok' => 50, # percentage | ||
| 147 | 'warning' => 5, | ||
| 148 | 'unknown' => 5, | ||
| 149 | 'critical' => 5, | ||
| 150 | 'pending' => 5, | ||
| 151 | 'flap' => 5, | ||
| 152 | 'random' => 25, | ||
| 153 | }, | ||
| 154 | ); | ||
| 155 | $ngt->create(); | ||
| 156 | ######################################################################### | ||
| 157 | |||
| 158 | sub add_dir { | ||
| 159 | my $dir = shift; | ||
| 160 | $opt_d = $dir; | ||
| 161 | return; | ||
| 162 | } |