DEV Community

Scotticles
Scotticles

Posted on • Updated on

Snipe-IT + Perl

I have a new module that is a work in progress, added to as needed. It's on github so you can add more api calls to it and submit a pull request to me. Its co-developed by me and my co-worker.

https://metacpan.org/pod/WWW::SnipeIT

What is Snipe-IT?

Snipe-IT is an open source asset management, to enable IT departments to track who has which laptop, when it was purchased, which software licenses and accessories are available, and so on. It can be self-hosted making it a great option for system administrators.

Purpose

We needed a way to interact with Snipe-IT from Perl for a Koha Plugin he is making.

At first, I set it up to use Moo for the object class but then with Perl Devs working towards Corinna with Object::Pad, I moved it to Object::Pad, the migration was super easy, but I am not using a ton of its features.

How to use

Firstly, you need a access token and the url to the Snipe-IT instance, if its https that would be preferred. This example its http.

use WWW::SnipeIT;

my $snipeIT = SnipeIT->new( endpoint => 'http://<mysnipeip>/api/v1/', accessToken => 'mylongapikey');
Enter fullscreen mode Exit fullscreen mode

Here is a basic example of pulling information on a asset tag.

https://snipe-it.readme.io/reference/api-overview

When creating this i tried to follow their structure with $snipe->{''} to make it easy to follow their guide.

my $snipe = $snipeIT->snipe();
my $result = $snipe->{'hardware'}->getHardwareIDByAssetTag(123);
say $result;
Enter fullscreen mode Exit fullscreen mode

And more examples on how to use it.

my $updateBody = '{"name":"Fruit Computer","notes":"Apple Computer"}';
my $searchBody = '{"name":"name","element":"text","field_values":"3Com"}';
my $assetTag = 123;
my $hardwareID = 321;
my $user = "Scott";
my $fieldName = "";
my $fieldValue = "3Com";
my $assetName = "3Com";
my $searchString = "ChromeBook";
my $categoryID = 3;
my $serialNumber = "abc1234";

warn Dumper($snipe->{'hardware'}->getHardwareIDByAssetTag($assetTag));
warn Dumper($snipe->{'hardware'}->getHardwareByAssetTag($assetTag));
warn Dumper($snipe->{'hardware'}->getAssetTagByHardwareID($hardwareID));
warn Dumper($snipe->{'hardware'}->updateAssetByHardwareID($hardwareID, $updateBody));
warn Dumper($snipe->{'hardware'}->updateAssetByAssetTag($assetTag, $updateBody));
warn Dumper($snipe->{'hardware'}->getHardwareByCustomField($fieldName, $user));
warn Dumper($snipe->{'hardware'}->getHardwareBySerialNumber($serialNumber));


warn Dumper($snipe->{'hardware'}->getHistoryByHardwareID($hardwareID));
warn Dumper($snipe->{'hardware'}->getHistoryByAssetTag($assetTag));
warn Dumper($snipe->{'hardware'}->searchHardware($searchString));

warn Dumper($snipe->{'hardware'}->getHardwareByCategory($categoryID));
Enter fullscreen mode Exit fullscreen mode

Its not fully featured but its a good start.

Top comments (4)

Collapse
 
janlimpens profile image
Jan

What does it do?

Collapse
 
scotticles profile image
Scotticles

Its a perl module so you can use perl to interact with your SnipeIT instance, snipeitapp.com/

Collapse
 
janlimpens profile image
Jan

I asked, because not everybody knows SnipeIT and it would be good info to put into the readme's / post's description to clear this up upfront.

Thread Thread
 
scotticles profile image
Scotticles

good thought, i updated the post.