I must be missing something here so I'm asking for more eyes on something.
I built a fairly simple straightforward module here and yet it is failing to work. This module does curls to an API (The Foreman) to extract some data from it. Nothing fancy here.... Here are the most important bits:
package NCS::PuppetDB::Data;
use 5.010000;
use strict;
use warnings;
use JSON;
our $curl="/usr/bin/curl -G 'http://localhost:8080/v3";
our $VERSION = '0.5.2';
sub new {
my $self={};
bless $self,"NCS::PupptDB::Data";
return $self;
}
sub getHosts {
my $self = shift;
my $cmd=sprintf("%s/nodes 2>/dev/null",$curl);
my $json = JSON->new->allow_nonref;
my $jsonData=`$cmd`;
my $decoded = $json->decode($jsonData);
my $retval=[];
for my $entry(@$decoded){
push @$retval,$entry->{name};
}
return sort $retval;
}
sub getHostFacts {
my $self = shift;
my $host = shift;
my $cmd=sprintf("%s/nodes/%s/facts' 2>/dev/null",$curl,$host);
my $json = JSON->new->allow_nonref;
my $jsonData=`$cmd`;
my $decoded = $json->decode($jsonData);
my $retval = {};
for my $fact(@$decoded){
$retval->{$fact->{name}} = $fact->{value};
}
return $retval;
}
sub getFact {
my ($self,$host,$factname)=@_;
my $facts=getHostFacts($host);
return $facts->{$factname};
}
1;
The one and only script using it (so far) is complaining:
Can't locate object method "getHosts" via package "NCS::PupptDB::Data"
What am I missing?
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net;
Blog: http://blog.berghold.net Warning: No political correctness allowed.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|