Modified: trunk/opsview-web/lib/Opsview/Web/Controller/REST/Status.pm
===================================================================
--- trunk/opsview-web/lib/Opsview/Web/Controller/REST/Status.pm 2012-07-13 10:23:13 UTC (rev 9558)
+++ trunk/opsview-web/lib/Opsview/Web/Controller/REST/Status.pm 2012-07-13 11:08:38 UTC (rev 9559)
@@ -75,16 +75,6 @@
$c->detach;
}
- my $object_params = {};
- foreach
- my $thing ( split ', ', $c->stash->{status_data}{service_selection} )
- {
- my ( $h, $s ) = split( ";", $thing );
- push @{ $object_params->{"svc.hs"} }, $h . "::" . $s;
- }
-
- $c->stash( object_params => $object_params );
-
# See which objects this should apply to
$c->forward( "find_objects" );
@@ -119,10 +109,12 @@
sub status_set : Private {
my ( $self, $c ) = @_;
- # my @hosts = @{ $c->stash->{hosts} || [] };
my @services = @{ $c->stash->{services} || [] };
- my $state = $c->req->param("state") || $c->stash->{status_data}{state};
+ my $state =
+ defined $c->req->param('new_state')
+ ? $c->req->param('new_state')
+ : $c->stash->{status_data}{state};
my $username = $c->user->name;
my $ackdata = $c->stash->{status_data};
@@ -143,54 +135,6 @@
done_services => [],
);
- # Host support not required right now, but left here so we can add it in
- # future.
- # foreach my $h (@hosts) {
-
- # my $command = Opsview::Externalcommand->new;
- # $command->command("PROCESS_HOST_CHECK_RESULT");
- # $command->args( join( ";", $h->name, $state, $comment, ) );
-
- # # Submitting a result is special:
- # # if on master, send to master,
- # # if on slave, send to all slaves (non-relevant ones will ignore)
- # # If you send to all, then master will get two results
- # # monitored_by is a column, not an object
- # my $result;
- # Opsview::Auditlog->create(
- # {
- # username => $c->user->username,
- # text => $c->translate(
- # "messages.auditlog.submittingHostCheckResultOnAs [_1] [_2] [_3]",
- # $h->name, $states_by_id->{$state}, $comment,
- # )
- # }
- # );
- # if ( ( $h->monitored_by || 0 ) == 1 ) {
- # eval { $result = $command->send_to_master };
- # }
- # else {
- # eval { $result = $command->send_to_slaves };
- # }
- # if ( !$@ ) {
- # push @{ $c->stash->{done_hosts} }, $h;
- # }
- # else {
- # my $error = $@;
- # push @{ $c->stash->{all_errors} }, $error;
- # Opsview::Auditlog->create(
- # {
- # username => $c->user->username,
- # text => $c->translate(
- # "messages.auditlog.submitCheckResult.failed [_1]",
- # $error
- # )
- # }
- # );
- # }
-
- # }
-
foreach my $s (@services) {
my $command = Opsview::Externalcommand->new;
@@ -242,17 +186,26 @@
}
-# Potentially could be called from web UI
sub status_validate : Private {
my ( $self, $c ) = @_;
my @errors;
- my $params = $c->req->params;
- my $data = "" || $c->req->data || {};
+ my $params = $c->req->params;
+ my $data = "" || $c->req->data || {};
+ my $state =
+ defined $data->{new_state} ? $data->{new_state}
+ : defined $data->{state} ? $data->{state}
+ : $c->req->param( 'new_state' );
my $comment = $data->{comment} || $params->{comment};
$comment = Opsview::Common->clean_comment($comment);
+ $c->forward( "/common/nagios_states", ["i_default"] );
+ unless ( grep { $_ eq $state } keys %{ $c->stash->{nagios_states_by_id} } )
+ {
+ push @errors, $c->loc( 'messages.state.noState' );
+ }
+
unless ($comment) {
push @errors, $c->loc( "ui.downtime.help.commentEmpty" );
}
@@ -278,11 +231,12 @@
$c->stash(
status_data => {
comment => $comment,
- state => $data->{state},
+ state => $state,
service_selection => $data->{service_selection},
}
);
}
+
}
__PACKAGE__->meta->make_immutable;
Modified: trunk/opsview-web/root/status/set
===================================================================
--- trunk/opsview-web/root/status/set 2012-07-13 10:23:13 UTC (rev 9558)
+++ trunk/opsview-web/root/status/set 2012-07-13 11:08:38 UTC (rev 9559)
@@ -21,7 +21,7 @@
</a>
</label>
-<select id="state" name="state">
+<select id="state" name="new_state">
[% FOREACH state IN nagios_states_by_id.keys.sort %]
<option value="[% state %]">[% nagios_states_by_id.$state | html %]</option>
[% END %]
Modified: trunk/opsview-web/t/675-service_status.t
===================================================================
--- trunk/opsview-web/t/675-service_status.t 2012-07-13 10:23:13 UTC (rev 9558)
+++ trunk/opsview-web/t/675-service_status.t 2012-07-13 11:08:38 UTC (rev 9559)
@@ -6,7 +6,7 @@
use Opsview::Test;
use Test::Deep;
-use Test::More tests => 14;
+use Test::More tests => 16;
use Test::WWW::Mechanize;
my $url_prefix = "http://localhost:3000";
@@ -46,17 +46,31 @@
ok( $data->{list}[10]{services}[1]{state} eq 'critical', "State is critical" );
$ua->post(
- "$url_prefix/rest/status",
+ "$url_prefix/rest/status?svc.serviceid=148&svc.serviceid=149&svc.serviceid=154",
Content => q`
{
- service_selection => "cisco;Another exception, cisco;Coldstart, cisco2;Another exception",
- state => 0,
- comment => sfgsd,
+ new_state => 4,
+ comment => 'sfgsd',
}
`
);
+is( $ua->status, 403, "Bad state detected" );
+is(
+ $ua->content,
+ "{'detail' => 'No new state defined','message' => 'Error validating status parameters'}",
+ "...with correct response"
+);
+
+$ua->post(
+ "$url_prefix/rest/status?svc.serviceid=148&svc.serviceid=149&svc.serviceid=154",
+ Content => q`
+ {
+ new_state => 0,
+ comment => 'sfgsd',
+ }
+ `
+);
is( $ua->status, 200, "Status change submitted OK" );
-
is_deeply(
$ua->content,
q`{'summary' => {'num_services' => '3','num_hosts' => '0'},'list' => {'hosts' => [],'services' => [{'id' => '148','hostname' => 'cisco','servicename' => 'Another exception'},{'id' => '149','hostname' => 'cisco','servicename' => 'Coldstart'},{'id' => '154','hostname' => 'cisco2','servicename' => 'Another exception'}]}}`,