Skip to content

Commit 91d51c4

Browse files
authored
Merge pull request solarwinds#15 from tonypnode/master
Correct node variable name and validate results
2 parents dfe99b9 + e011400 commit 91d51c4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

samples/unmanage_node.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ def main():
99
password = ''
1010

1111
swis = SwisClient(hostname, username, password)
12-
results = swis.query('SELECT TOP 1 NodeID FROM Orion.Nodes')
13-
interfaceId = results['results'][0]['NodeID']
14-
netObjectId = 'N:{}'.format(interfaceId)
15-
now = datetime.utcnow()
16-
tomorrow = now + timedelta(days=1)
17-
swis.invoke('Orion.Nodes', 'Unmanage', netObjectId, now, tomorrow, False)
12+
results = swis.query('SELECT NodeID, Caption FROM Orion.Nodes WHERE IPAddress = @ip_addr', ip_addr='127.0.0.1')
13+
if results['results']:
14+
nodeId = results['results'][0]['NodeID']
15+
caption = results['results'][0]['Caption']
16+
netObjectId = 'N:{}'.format(nodeId)
17+
now = datetime.utcnow()
18+
tomorrow = now + timedelta(days=1)
19+
swis.invoke('Orion.Nodes', 'Unmanage', netObjectId, now, tomorrow, False)
20+
print('Done...{} will be unmanaged until {}'.format(caption, tomorrow))
21+
else:
22+
print("Device doesn't Exist")
1823

1924

2025
requests.packages.urllib3.disable_warnings()

0 commit comments

Comments
 (0)