+ Some cleaning on openweathermap plugin
This commit is contained in:
parent
2084cef531
commit
cc8b1285f8
|
@ -123,24 +123,6 @@ sub settings {
|
||||||
$self->{http}->set_options(%{$self->{option_results}});
|
$self->{http}->set_options(%{$self->{option_results}});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_connection_info {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
return $self->{hostname} . ":" . $self->{port};
|
|
||||||
}
|
|
||||||
|
|
||||||
sub get_hostname {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
return $self->{hostname};
|
|
||||||
}
|
|
||||||
|
|
||||||
sub get_port {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
return $self->{port};
|
|
||||||
}
|
|
||||||
|
|
||||||
sub set_token {
|
sub set_token {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
push @{$self->{get_param}}, 'APPID=' . $self->{api_token};
|
push @{$self->{get_param}}, 'APPID=' . $self->{api_token};
|
||||||
|
@ -152,13 +134,11 @@ sub request_api {
|
||||||
$self->set_token();
|
$self->set_token();
|
||||||
$self->settings;
|
$self->settings;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Query URL: '" . $self->{proto} . "://" . $self->{hostname} .
|
|
||||||
$self->{url_path} . $options{url_path} . "'", debug => 1);
|
|
||||||
|
|
||||||
foreach my $get_param (@{$options{get_param}}) {
|
foreach my $get_param (@{$options{get_param}}) {
|
||||||
push @{$self->{get_param}}, $get_param;
|
push @{$self->{get_param}}, $get_param;
|
||||||
}
|
}
|
||||||
my $content = $self->{http}->request(url_path => $self->{url_path} . $options{url_path},
|
my $content = $self->{http}->request(
|
||||||
|
url_path => $self->{url_path} . $options{url_path},
|
||||||
get_param => \@{$self->{get_param}}
|
get_param => \@{$self->{get_param}}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ sub set_counters {
|
||||||
},
|
},
|
||||||
{ label => 'temperature', nlabel => 'temperature.celsius', set => {
|
{ label => 'temperature', nlabel => 'temperature.celsius', set => {
|
||||||
key_values => [ { name => 'temperature' } ],
|
key_values => [ { name => 'temperature' } ],
|
||||||
output_template => 'Temperature: %d C°',
|
output_template => 'Temperature: %d C',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'temperature', value => 'temperature_absolute', template => '%d',
|
{ label => 'temperature', value => 'temperature_absolute', template => '%d',
|
||||||
unit => 'C' }
|
unit => 'C' }
|
||||||
|
@ -126,10 +126,10 @@ sub check_options {
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{city} = {};
|
my $results = $options{custom}->request_api(
|
||||||
|
url_path => "/weather?",
|
||||||
my $results = $options{custom}->request_api(url_path => "/weather?",
|
get_param => ["q=" . $self->{option_results}->{city_name}]
|
||||||
get_param => ["q=" . $self->{option_results}->{city_name}]);
|
);
|
||||||
|
|
||||||
$self->{city} = {
|
$self->{city} = {
|
||||||
wind => $results->{wind}->{speed},
|
wind => $results->{wind}->{speed},
|
||||||
|
@ -138,11 +138,6 @@ sub manage_selection {
|
||||||
clouds => $results->{clouds}->{all},
|
clouds => $results->{clouds}->{all},
|
||||||
weather => @{$results->{weather}->[0]}{main}
|
weather => @{$results->{weather}->[0]}{main}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (scalar(keys %{$self->{city}}) <= 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "No city found.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in New Issue