Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection failure parsed as json #23

Open
richlv opened this issue Jun 5, 2017 · 7 comments
Open

connection failure parsed as json #23

richlv opened this issue Jun 5, 2017 · 7 comments

Comments

@richlv
Copy link
Collaborator

richlv commented Jun 5, 2017

not completely sure whether this is something fixable in Zabbix::Tiny, but the current behaviour seems hard to handle on the module-using side.

if the connection to the api fails, the outcome is :

malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "Can't connect to za....") at /usr/lib/perl5/site_perl/5.18.2/Zabbix/Tiny.pm line 149, <STDIN> line 2.

it would be great if the connection failure could be detected and there was a suggested way to detect it (so that the module user could retry, for example)

@whosgonna
Copy link
Owner

Is there a code sample for this? Jus an unreachable URL or something?

It will depend on where the message comes from, but it might be possible to provide exception handling.

@richlv
Copy link
Collaborator Author

richlv commented Jun 5, 2017

it is a connection failure - i suspect a dns lookup failure could result in this

@whosgonna
Copy link
Owner

It looks like the failure to connect is passed up the chain, and it should die (or probably more appropriately croak) there. The change would be in the error message - changing from the malformed JSON string message to the Can't connect to za.... error.

This can then be more appropriately handled via something like Try::Tiny or similar exception handling modules.

@whosgonna
Copy link
Owner

whosgonna commented Jul 21, 2017

Richlv,

I tested with a bogus DNS name, and I get a very clean error:

HTTP error (code 500) Can't connect to zabbix.domain.fake:443 at ./iss23.pl line 23

Here's my test code:

#!/usr/bin/env perl
use strict;
use warnings;
use Zabbix::Tiny;
use Data::Dumper;

my $zabbix = Zabbix::Tiny->new(
    server   => 'https://zabbix.domain.fake',
    password => 'whosgonna',
    user     => 'fakepass',
);


my $hosts = $zabbix->do( 'host.get' );

print Dumper $hosts;

I KNOW that i had seen errors like you state before, but I'm not getting them now. Are you able to reproduce?

@richlv
Copy link
Collaborator Author

richlv commented Jul 21, 2017

haven't tried to reproduce at will, but i believe it might be resulting from a dns lookup failure, not from a negative lookup (where the actual request succeeded)

@whosgonna
Copy link
Owner

Let me know if you find a way to reproduce it. It looks like the error message in the original report is the same as the failure I'm getting now - I'm just getting it cleanly. That is to say that rather than get a JSON encoding error like:
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "Can't connect to za....") at /usr/lib/perl5/site_perl/5.18.2/Zabbix/Tiny.pm line 149, <STDIN> line 2

I get the actual contents of the message:
Can't connect to www.domain.fake:443 at ./iss23.pl line 14.

As I said, I actually observed the same error at one point shortly after you reported this (the script was run with cron, so i never got around to debugging it at the time), so I have seem the same problem as well, but I'm not able to reproduce. Let me know what you find, but for the sake of 'cleanliness' I'm going to close this issue in a week if we can't figure out how to reproduce (it's easy to re-open :) )

Thank you!

@richlv
Copy link
Collaborator Author

richlv commented Jul 22, 2017

thank you a lot, makes sense. will try to reproduce it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants