+ 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}});
|
||||
}
|
||||
|
||||
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 {
|
||||
my ($self, %options) = @_;
|
||||
push @{$self->{get_param}}, 'APPID=' . $self->{api_token};
|
||||
|
@ -152,15 +134,13 @@ sub request_api {
|
|||
$self->set_token();
|
||||
$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}}) {
|
||||
push @{$self->{get_param}}, $get_param;
|
||||
}
|
||||
my $content = $self->{http}->request(url_path => $self->{url_path} . $options{url_path},
|
||||
get_param => \@{$self->{get_param}}
|
||||
);
|
||||
my $content = $self->{http}->request(
|
||||
url_path => $self->{url_path} . $options{url_path},
|
||||
get_param => \@{$self->{get_param}}
|
||||
);
|
||||
|
||||
my $decoded;
|
||||
eval {
|
||||
|
|
|
@ -58,7 +58,7 @@ sub set_counters {
|
|||
},
|
||||
{ label => 'temperature', nlabel => 'temperature.celsius', set => {
|
||||
key_values => [ { name => 'temperature' } ],
|
||||
output_template => 'Temperature: %d C°',
|
||||
output_template => 'Temperature: %d C',
|
||||
perfdatas => [
|
||||
{ label => 'temperature', value => 'temperature_absolute', template => '%d',
|
||||
unit => 'C' }
|
||||
|
@ -126,10 +126,10 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{city} = {};
|
||||
|
||||
my $results = $options{custom}->request_api(url_path => "/weather?",
|
||||
get_param => ["q=" . $self->{option_results}->{city_name}]);
|
||||
my $results = $options{custom}->request_api(
|
||||
url_path => "/weather?",
|
||||
get_param => ["q=" . $self->{option_results}->{city_name}]
|
||||
);
|
||||
|
||||
$self->{city} = {
|
||||
wind => $results->{wind}->{speed},
|
||||
|
@ -138,11 +138,6 @@ sub manage_selection {
|
|||
clouds => $results->{clouds}->{all},
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue