File Coverage

blib/lib/Net/SolarWinds/Helper.pm
Criterion Covered Total %
statement 51 60 85.0
branch n/a
condition n/a
subroutine 17 20 85.0
pod 3 3 100.0
total 71 83 85.5


line stmt bran cond sub pod time code
1             package Net::SolarWinds::Helper;
2              
3 2     2   11 use strict;
  2         3  
  2         44  
4 2     2   7 use warnings;
  2         2  
  2         252  
5              
6             =head1 NAME
7              
8             Net::SolarWinds::Helper - Common OO Methods
9              
10             =head1 SYNOPSIS
11              
12             use base qw(Net::SolarWinds::Helper);
13              
14             =head1 DESCRIPTION
15              
16             This class provides common OO methods used to for Solarwinds development. These methods are all stand alone.
17              
18             =over 4
19              
20             =item * my $reverse_hex=$self->ip_to_reverse_hex($ip);
21              
22             Converts an IP into hex with the octets swapped to reverse order.
23              
24             =cut
25              
26             sub ip_to_reverse_hex {
27              
28 0     0 1   my ($self,$ip)=@_;
29              
30 0           my $hex=unpack("H8",reverse(pack("C4",split(/\./,$ip))));
31              
32 0           return $hex;
33             }
34              
35             =item * my $gui_ip=$self->ip_to_gui($ip);
36              
37             Converts a quad notation ip to the gui display version SolarWinds uses..
38              
39             =cut
40              
41             sub ip_to_gui {
42 0     0 1   my ($self,$ip)=@_;
43              
44 0           my $hex=$self->ip_to_reverse_hex($ip);
45              
46 0           $hex .="-0000-0000-0000-000000000000";
47              
48 0           return $hex;
49             }
50              
51             =item * my $swis=$self->nodeUri($node_id);
52              
53             Returns the node Uri based on the $node_id
54              
55             =cut
56              
57             sub nodeUri {
58 0     0 1   my ($self,$nodeId)=@_;
59 0           return "swis://localhost/Orion/Orion.Nodes/NodeID=$nodeId";
60             }
61              
62             =back
63              
64             =head1 Query Drivers
65              
66             Many of the internals use site spesific SWQL statements, they are defined as constants in this class. Since some of these queries are Solarwinds install spesific it may be required to overload some of these queries.
67              
68             =head2 Query Drivers For: Net::SolarWinds::REST
69              
70             =over 4
71              
72             =item * my $sql=$self->SWQL_getInterfacesOnNode;
73              
74             =cut
75              
76 2     2   9 use constant SWQL_getInterfacesOnNode=>'SELECT Caption, InterfaceID, DisplayName, FullName, ifname, interfacetype as ifType FROM Orion.NPM.Interfaces where NodeID=%s';
  2         2  
  2         118  
77              
78             =item * my $sql=$self->SWQL_getNodesByDisplayName;
79              
80             =cut
81              
82 2         85 use constant SWQL_getNodesByDisplayName=>q{SELECT
83             NodeID,
84             IPAddress,
85             IPAddressGUID,
86             Caption,
87             DynamicIP,
88             EngineID,
89             Status,
90             UnManaged,
91             Allow64BitCounters,
92             ObjectSubType,
93             SysObjectID,
94             MachineType,
95             VendorIcon,
96             SNMPVersion,
97             Community,
98             RediscoveryInterval,
99             PollInterval,
100             StatCollection,
101             Uri,
102             DisplayName
103 2     2   7 FROM Orion.Nodes where DisplayName='%s' OR Caption='%s'};
  2         2  
104              
105             =item * my $sql=$self->SWQL_getNodesByID;
106              
107             =cut
108              
109 2         70 use constant SWQL_getNodesByID=>q{SELECT
110             NodeID,
111             IPAddress,
112             IPAddressGUID,
113             Caption,
114             DynamicIP,
115             EngineID,
116             Status,
117             UnManaged,
118             Allow64BitCounters,
119             ObjectSubType,
120             SysObjectID,
121             MachineType,
122             VendorIcon,
123             SNMPVersion,
124             Community,
125             RediscoveryInterval,
126             PollInterval,
127             StatCollection,
128             Uri
129 2     2   7 FROM Orion.Nodes where NodeId='%s'};
  2         2  
130              
131             =item * my $sql=$self->SWQL_getApplicationTemplate;
132              
133             =cut
134              
135 2     2   7 use constant SWQL_getApplicationTemplate=>q{SELECT ApplicationTemplateID, Created, CustomApplicationType, Description, DisplayName, HasImportedView, InstanceType, IsMockTemplate, LastModified, Name, Uri, ViewID, ViewXml FROM Orion.APM.ApplicationTemplate where %s};
  2         9  
  2         77  
136              
137             =item * my $sql=$self->SWQL_getTemplatesOnNode;
138              
139             =cut
140              
141 2     2   6 use constant SWQL_getTemplatesOnNode=>q{SELECT ApplicationID, ApplicationTemplateID, Description, DetailsUrl, DisplayName, HasCredentials, ID, InstanceType, Name, NodeID, Uri FROM Orion.APM.Application where nodeid=%s};
  2         2  
  2         85  
142              
143             =item * my $sql=$self->SWQL_getNodesByIp;
144              
145             =cut
146              
147 2         71 use constant SWQL_getNodesByIp=>q{SELECT
148             NodeID,
149             IPAddress,
150             IPAddressGUID,
151             Caption,
152             DynamicIP,
153             EngineID,
154             Status,
155             UnManaged,
156             Allow64BitCounters,
157             ObjectSubType,
158             SysObjectID,
159             MachineType,
160             VendorIcon,
161             SNMPVersion,
162             Community,
163             RediscoveryInterval,
164             PollInterval,
165             StatCollection,
166             Uri,
167             DisplayName
168 2     2   6 FROM Orion.Nodes where IP_Address='%s'};
  2         3  
169              
170             =item * my $sql=$self->SWQL_getVolumeTypeMap;
171              
172             =cut
173              
174 2     2   6 use constant SWQL_getVolumeTypeMap=>q{SELECT distinct VolumeType, VolumeTypeIcon, VolumeTypeID FROM Orion.Volumes};
  2         2  
  2         77  
175              
176             =item * my $sql=$self->SWQL_getEngines;
177              
178             =cut
179              
180 2     2   7 use constant SWQL_getEngines=>q{SELECT AvgCPUUtil, BusinessLayerPort, CompanyName, CustomerID, Description, DisplayName, Elements, EngineID, EngineVersion, EvalDaysLeft, Evaluation, FailOverActive, FIPSModeEnabled, InstanceType, InterfacePollInterval, Interfaces, InterfaceStatPollInterval, IP, KeepAlive, LicensedElements, LicenseKey, MaxPollsPerSecond, MaxStatPollsPerSecond, MemoryUtil, MinutesSinceFailOverActive, MinutesSinceKeepAlive, MinutesSinceRestart, MinutesSinceStartTime, MinutesSinceSysLogKeepAlive, MinutesSinceTrapsKeepAlive, NodePollInterval, Nodes, NodeStatPollInterval, PackageName, Pollers, PollingCompletion, PrimaryServers, Restart, SerialNumber, ServerName, ServerType, ServicePack, StartTime, StatPollInterval, SysLogKeepAlive, TrapsKeepAlive, Uri, VolumePollInterval, Volumes, VolumeStatPollInterval, WindowsVersion FROM Orion.Engines};
  2         2  
  2         81  
181              
182             =item * my $sql=$self->SWQL_getNodeUri;
183              
184             =cut
185              
186 2     2   7 use constant SWQL_getNodeUri=>'Select Uri from Orion.Nodes where NodeId=%s';
  2         2  
  2         86  
187              
188             =item * my $sql=$self->SWQL_getEngine;
189              
190             =cut
191              
192 2     2   8 use constant SWQL_getEngine=>q{SELECT AvgCPUUtil, BusinessLayerPort, CompanyName, CustomerID, Description, DisplayName, Elements, EngineID, EngineVersion, EvalDaysLeft, Evaluation, FailOverActive, FIPSModeEnabled, InstanceType, InterfacePollInterval, Interfaces, InterfaceStatPollInterval, IP, KeepAlive, LicensedElements, LicenseKey, MaxPollsPerSecond, MaxStatPollsPerSecond, MemoryUtil, MinutesSinceFailOverActive, MinutesSinceKeepAlive, MinutesSinceRestart, MinutesSinceStartTime, MinutesSinceSysLogKeepAlive, MinutesSinceTrapsKeepAlive, NodePollInterval, Nodes, NodeStatPollInterval, PackageName, Pollers, PollingCompletion, PrimaryServers, Restart, SerialNumber, ServerName, ServerType, ServicePack, StartTime, StatPollInterval, SysLogKeepAlive, TrapsKeepAlive, Uri, VolumePollInterval, Volumes, VolumeStatPollInterval, WindowsVersion FROM Orion.Engines where ServerName='%s' or DisplayName='%s'};
  2         1  
  2         81  
193              
194             =item * my $sql=$self->SWQL_getVolumeMap;
195              
196             =cut
197              
198 2         63 use constant SWQL_getVolumeMap=>q{SELECT
199             VolumeIndex,
200             Caption,
201             VolumeDescription,
202             Status,
203             Type ,
204             Icon ,
205             VolumeSpaceAvailable,
206             VolumeSize,
207             VolumePercentUsed,
208             VolumeSpaceUsed,
209             VolumeTypeID,
210             PollInterval,
211             StatCollection,
212             RediscoveryInterval,
213             VolumeID,
214             NodeID
215              
216 2     2   7 FROM Orion.Volumes where NodeID=%s};
  2         2  
217              
218             =item * my $sql=$self->SWQL_GetNodePollers;
219              
220             =cut
221              
222 2     2   7 use constant SWQL_GetNodePollers=>q{SELECT Description, DisplayName, Enabled, InstanceType, NetObject, NetObjectID, NetObjectType, PollerID, PollerType, Uri FROM Orion.Pollers where NetObjectID=%s and NetObjectType='%s'};
  2         2  
  2         85  
223              
224             =back
225              
226             =head2 Query Drivers For: Net::SolarWinds::REST::Batch
227              
228             =over 4
229              
230             =item * my $sql=$self->SWQL_getPollerInterfaceMap;
231              
232             =item * my $sql=$self->SWQL_GetNodeInterfacePollers;
233              
234             =item * my $sql=$self->SWQL_get_poller_map;
235              
236             =cut
237              
238 2         74 use constant SWQL_getPollerInterfaceMap=>q{select
239             p.PollerType,
240             i.interfacetype as ifType,
241             count(i.interfaceid) as totalinterfaces
242             FROM
243             Orion.NPM.Interfaces as i
244             inner join Orion.Pollers as p on i.InterfaceID=p.NetObjectID and p.NetObjectType='I'
245             where
246             i.NodeID=%s
247 2     2   7 group by p.PollerType,i.interfacetype};
  2         2  
248              
249              
250 2         64 use constant SWQL_GetNodeInterfacePollers=>q{select
251             p.PollerType,
252             i.interfacetype as ifType,
253             i.InterfaceName as ifName,
254             i.InterfaceID,
255             i.Uri as InterfaceUri,
256             p.Uri as PollerUri
257             FROM
258             Orion.NPM.Interfaces as i
259             left join Orion.Pollers as p on i.InterfaceID=p.NetObjectID and p.NetObjectType='I'
260             where
261             i.NodeID=%s
262 2     2   7 order by i.InterfaceID};
  2         2  
263              
264              
265 2     2   6 use constant SWQL_get_poller_map=>q{SELECT Description, DisplayName, Enabled, InstanceType, NetObject, NetObjectID, NetObjectType, PollerID, PollerType, Uri FROM Orion.Pollers where NetObjectID=%s and NetObjectType='%s'};
  2         2  
  2         67  
266              
267             =back
268              
269             =head1 Author
270              
271             Michael Shipper
272              
273             =cut
274              
275             1;
276              
277             __END__