I have the following code :
for nodeid,nodeip in zip(node['id'], node['ip']):
nodeurl = url.format(nodeid, nodeip)
x = requests.get(nodeurl,headers=headers , auth=('admin', '0p3nNM$2015'))
parsed = json.loads(x.content)
##print json.dumps(parsed, indent=4, sort_keys=True)
for i in parsed["service"]:
#print i["serviceType"]["name"]
if i["serviceType"]["name"]=="SSH":
print "OpenNMS BOT Found the following IP: " ## How to print it just ONCE
print nodeip
slack.chat.post_message(slack_channel,">>>"+nodeip,username='OPENNMS_FRA_BOT')
else:
print "No IP found with SSH running"
So the thing is, this code works fine. All I want now is just to have the following type of output if a IP is found with the mentioned condition:
OpenNMS BOT Found the following IP:
10.0.0.1
10.0.0.2
10.0.0.3
.
.
.
so on
But the above code prints
OpenNMS BOT Found the following IP:
10.0.0.1
OpenNMS BOT Found the following IP:
10.0.0.2
OpenNMS BOT Found the following IP:
10.0.0.3
.
.
.
so on
ifclause to check whether the current IP is the first one to be found.