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

Allow setting LWP::UserAgent options #25

Open
whosgonna opened this issue Sep 5, 2017 · 2 comments
Open

Allow setting LWP::UserAgent options #25

whosgonna opened this issue Sep 5, 2017 · 2 comments

Comments

@whosgonna
Copy link
Owner

@richlv noted he was having trouble with requests being rejected due to mod-security, and not having an Allow header set.

I think it should be pretty easy to address this by adding an attribute for UA arguments, and then passing those args to the UA instantiation.

@whosgonna
Copy link
Owner Author

I just pushed a change to the iss25 branch that should address this, but i don't currently really have any way of testing it, so it's kind of a shot in the dark....

whosgonna pushed a commit that referenced this issue Sep 8, 2017
@whosgonna
Copy link
Owner Author

whosgonna commented Sep 8, 2017

I've pushed 3f40a5d to branch iss25 change that should work. The new() now accepts an argument of lwp_attrs that will be passed to the LWP::UserAgent->new(%options). I don't recall the specific headers that were needing to be set, but this code should work (just update the header values portion)

#!/usr/bin/env perl
use strict;
use warnings;
use lib "Zabbix::Tiny/lib/";  ##Set path as appropriate.
use Zabbix::Tiny;
use Data::Printer;

my $zabbix = Zabbix::Tiny->new(
    server    => 'https://zabbix.domain.com.com/api_jsonrpc.php',
    password  => 'password',
    user      => 'username',
    lwp_attrs => {
        default_headers => HTTP::Headers->new(
            'x-my-header' => 'some value here'
        ),
    },
);

my $hosts = $zabbix->do(
    'host.get', {
        output          => [qw(hostid name host)],
        monitored_hosts => 1,
        limit           => 1,
    }
);

p $hosts;

I'm considering just adding an 'http_headers' value that can be set in Zabbix::Tiny's new, but that would just be a small wrapper around those arguments, and it philosophically undercuts the "tiny" aspect of the module (which is to automate the server interaction only). If it looks like this is something that will be typed frequently, then i might add a convenience method, but it would only be called once during instantiation, and it would only change this:

lwp_attrs => {
    default_headers => HTTP::Headers->new(
        'x-my-header' => 'some value here'
    ),
}

To this:

http_headers => {
    'x-my-header' => 'some value here'
},

Either way, the lwp_attrs will remain, as it allows access to the remainder of the LWP configuration.

Let me know if the sample code works for you, and if so, i'll begin on the documentation (and...unit tests? maybe?)

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

1 participant