Changeset 254
- Timestamp:
- Jun 25, 2018, 5:07:25 PM (7 years ago)
- Location:
- trunk/nagios-velvice
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nagios-velvice/velvice.cgi
r250 r254 34 34 $config->{'downtime'}{'max'} ||= 50; 35 35 $config->{'downtime'}{'factor'} ||= 0.7; 36 $config->{' service'}||= {};36 $config->{'action'} ||= {}; 37 37 38 38 my $query = CGI->new(); … … 132 132 ENDH 133 133 134 my %service_name = ();135 my %service_ level= ();134 my %service_name = (); 135 my %service_status = (); 136 136 for my $srv (@serviceproblems) { 137 137 $service_name{$srv->service_description}++; 138 $service_ level{$srv->status}++;138 $service_status{$srv->status}++; 139 139 } 140 140 … … 147 147 $htmlpage .= join ",\n", 148 148 " <a href='$script_name?check=all'>ALL</a><small>(" . scalar(@serviceproblems) . ')</small>', 149 map(" <a href='$script_name?check=" . lc(uri_encode($_)) . "'>$_</a>($service_ level{$_})", sort keys %service_level);149 map(" <a href='$script_name?check=" . lc(uri_encode($_)) . "'>$_</a>($service_status{$_})", sort keys %service_status); 150 150 $htmlpage .= ".\n"; 151 151 $htmlpage .= " <br />\n"; … … 158 158 open $nagios_cmd, '>>', $config->{'nagios-cmd'} or die "Can't open file filename: $!"; 159 159 160 my % sshdown= ();161 my % cmdafter= ();162 my $ after;160 my %remote_sshdown = (); 161 my %remote_db = (); 162 my $remote_flag; 163 163 164 164 my $current_host = ''; 165 165 $htmlpage .= "<table border=\"1\">\n"; 166 SERVICE_PROBLEMS: 166 167 for my $srv (@serviceproblems) { 167 168 my $hostname = $srv->host_name; … … 181 182 182 183 my $bold; 183 for my $srv_name (keys %{$config->{'service'}}) { 184 my $srv_regex = $config->{'service'}{$srv_name}{'regex'}; 185 $bold++ if $service =~ m/$srv_regex/ and $config->{'service'}{$srv_name}{'style'} eq 'bold'; 184 ACTION_STYLE: 185 for my $act_name (keys %{$config->{'action'}}) { 186 my $act_regex = $config->{'action'}{$act_name}{'regex'}; 187 $bold++ if $service =~ m/$act_regex/ and $config->{'action'}{$act_name}{'style'} eq 'bold'; 186 188 } 187 189 $htmlpage .= $bold ? ' <td class="bold">' : ' <td>'; … … 190 192 $htmlpage .= " <td>$status</td>\n"; 191 193 $htmlpage .= " <td style='max-width:60%;'><small>$output"; 192 193 $sshdown{$hostname}++ if $service eq 'SSH';194 194 195 195 if (($check =~ m/all/i) … … 211 211 } 212 212 213 for my $srv_name (keys %{$config->{'service'}}) { 214 my $srv_regex = $config->{'service'}{$srv_name}{'regex'}; 215 my $srv_status = $config->{'service'}{$srv_name}{'status'}; 216 if ($service =~ m/$srv_regex/ and ($srv_status eq 'ALL' or $status =~ m/$srv_status/)) { 217 $cmdafter{$srv_name} ||= []; 218 push @{$cmdafter{$srv_name}}, $hostname; 219 $after++; 213 ACTION_PUSH_AND_DEPEND: 214 for my $act_name (keys %{$config->{'action'}}) { 215 my $act_regex = $config->{'action'}{$act_name}{'regex'}; 216 my $act_status = $config->{'action'}{$act_name}{'status'} || 'ALL'; 217 my $act_depend = $config->{'action'}{$act_name}{'depend'} || 'SSH'; 218 219 if ($service =~ m/$act_regex/ and ($act_status eq 'ALL' or $status =~ m/$act_status/)) { 220 $remote_db{$act_name} ||= []; 221 push @{$remote_db{$act_name}}, $hostname; 222 $remote_flag++; 220 223 } 224 225 # check depend service otherwise 226 $remote_sshdown{$act_depend} ||= {}; 227 $remote_sshdown{$act_depend}->{$hostname}++ if $service =~ m/$act_depend/; 221 228 } 222 229 … … 229 236 close $nagios_cmd; 230 237 238 # host down 231 239 if (%hostdown) { 232 240 $htmlpage .= "<br />\n"; 233 241 $htmlpage .= "<table border='1'>\n"; 242 HOST_DOWN: 234 243 for my $host (sort keys %hostdown) { 235 244 my $host_stat = $hostdown{$host}; … … 250 259 } 251 260 252 if ($after) { 261 # remote action 262 if ($remote_flag) { 253 263 require Nagios::Object::Config; 254 264 my $parser = Nagios::Object::Config->new(); 255 265 $parser->parse("/var/cache/nagios3/objects.cache"); 256 266 257 for my $srv_name (keys %cmdafter) { 258 my @action = grep !exists $sshdown{$_}, @{$cmdafter{$srv_name}}; 267 REMOTE_ACTION: 268 for my $act_name (keys %remote_db) { 269 my $act_depend = $config->{'action'}{$act_name}{'depend'} || 'SSH'; 270 271 my @action = grep !exists $remote_sshdown{$act_depend}->{$_}, @{$remote_db{$act_name}}; 259 272 if (@action) { 260 my $srv_title = $config->{' service'}{$srv_name}{'title'} || "Action: $srv_name";273 my $srv_title = $config->{'action'}{$act_name}{'title'} || "Action: $act_name"; 261 274 $htmlpage .= "<h2>$srv_title</h2>\n"; 262 275 $htmlpage .= "<pre>\n"; 263 my $remote_action = $config->{' service'}{$srv_name}{'command'};264 $remote_action = $config->{' service'}{$srv_name}{'command-one'} if @action == 1;276 my $remote_action = $config->{'action'}{$act_name}{'command'}; 277 $remote_action = $config->{'action'}{$act_name}{'command-one'} if @action == 1 and exists $config->{'action'}{$act_name}{'command-one'}; 265 278 my @hosts; 266 279 for my $host (@action) { … … 283 296 print $htmlpage; 284 297 285 # delay future check298 # delayed future check 286 299 if (@futurecheck) { 287 300 sleep 2; -
trunk/nagios-velvice/velvice.sample.yml
r248 r254 15 15 factor: 0.7 16 16 17 service:17 action: 18 18 oom-killer: 19 19 regex: ^OOM Killer
Note: See TracChangeset
for help on using the changeset viewer.