line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::SnipeIT::Hardware; |
2
|
1
|
|
|
1
|
|
6
|
use Modern::Perl '2018'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
167
|
use Object::Pad; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
442
|
use HTTP::Request; |
|
1
|
|
|
|
|
17167
|
|
|
1
|
|
|
|
|
35
|
|
7
|
1
|
|
|
1
|
|
656
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
25850
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
688
|
use JSON::XS; |
|
1
|
|
|
|
|
4602
|
|
|
1
|
|
|
|
|
150
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
class Hardware { |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has $endpoint :param; |
14
|
|
|
|
|
|
|
has $header :param; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
|
|
method getHardwareIDByAssetTag ($assetTag) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $url = $endpoint."hardware/bytag/".$assetTag; |
20
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('GET', $url, $header); |
21
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
22
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
23
|
0
|
|
|
|
|
|
my $results = JSON::XS::decode_json($res->{_content}); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return $results->{'id'} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
|
|
method getHardwareByAssetTag ($assetTag) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $url = $endpoint."hardware/bytag/".$assetTag; |
30
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('GET', $url, $header); |
31
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
32
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
33
|
0
|
|
|
|
|
|
my $results = JSON::XS::decode_json($res->{_content}); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $results |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
|
|
method getHardwareBySerialNumber ($serialNumber) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $url = $endpoint."hardware/byserial/".$serialNumber; |
40
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('GET', $url, $header); |
41
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
42
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
43
|
0
|
|
|
|
|
|
my $results = JSON::XS::decode_json($res->{_content}); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return $results |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
|
|
method getAssetTagByHardwareID ($hardwareID) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $url = $endpoint."hardware/".$hardwareID; |
50
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('GET', $url, $header); |
51
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
52
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
53
|
0
|
|
|
|
|
|
my $results = JSON::XS::decode_json($res->{_content}); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $results->{'asset_tag'} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
0
|
|
|
method updateAssetByHardwareID ($hardwareID, $body) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $url = $endpoint."hardware/".$hardwareID; |
60
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('PUT', $url, $header, $body); |
61
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
62
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
0
|
|
|
method updateAssetByAssetTag ($assetTag, $body) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $hardwareID = ($self->getHardwareIDByAssetTag($assetTag)); |
67
|
0
|
|
|
|
|
|
$self->updateAssetByHardwareID ($hardwareID, $body) |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
|
|
method getHardwareByCustomField ($fieldName, $fieldValue, $itemType = 'asset') { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $url = $endpoint."hardware?".$fieldName."=".$fieldValue."&item_type=".$itemType; |
72
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('GET', $url, $header); |
73
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
74
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
75
|
0
|
|
|
|
|
|
my $results = JSON::XS::decode_json($res->{_content}); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return $results; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
0
|
|
|
method getHistoryByHardwareID ($hardwareID, $itemType = 'asset') { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $url = $endpoint."reports/activity?item_id=".$hardwareID."&item_type=".$itemType; |
82
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('GET', $url, $header); |
83
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
84
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
85
|
0
|
|
|
|
|
|
my $results = JSON::XS::decode_json($res->{_content}); |
86
|
0
|
|
|
|
|
|
return $results; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
|
|
method getHistoryByAssetTag ($assetTag, $itemType = 'asset') { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $hardwareID = ($self->getHardwareIDByAssetTag($assetTag)); |
91
|
0
|
|
|
|
|
|
return $self->getHistoryByHardwareID($hardwareID); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
|
|
method searchHardware ($searchString) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $url = $endpoint."hardware?search=".$searchString; |
96
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('GET', $url, $header); |
97
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
98
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
99
|
0
|
|
|
|
|
|
my $results = JSON::XS::decode_json($res->{_content}); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $results; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
0
|
|
|
method getHardwareByCategory ($searchString) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $url = $endpoint."hardware?category_id=".$searchString; |
106
|
0
|
|
|
|
|
|
my $r = HTTP::Request->new('GET', $url, $header); |
107
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
108
|
0
|
|
|
|
|
|
my $res = $ua->request($r); |
109
|
0
|
|
|
|
|
|
my $results = JSON::XS::decode_json($res->{_content}); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $results; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|