Skip to content

Instantly share code, notes, and snippets.

@r3dact3d
Last active February 27, 2017 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r3dact3d/a39978342e95d2f8e8907341d284abab to your computer and use it in GitHub Desktop.
Save r3dact3d/a39978342e95d2f8e8907341d284abab to your computer and use it in GitHub Desktop.
Python script to enable or disable Nagios Host and Host Services
#!/usr/bin/env python
# written by Brady r3dact3d
#
import sys, os, time
try:
hostList = sys.argv[1]
action = sys.argv[2]
except:
print("[-] Please pass txt file with hostnames and either enable/disable")
print("[-] ./nagiosDowntime.py hosts.txt enable or disable")
sys.exit(0)
def changeNotif(status):
commandFile = '/usr/local/nagios/var/rw/nagios.cmd'
pipeOut = os.open(commandFile, os.O_WRONLY)
os.write(pipeOut, status)
os.close(pipeOut)
time.sleep(1)
def motive(action, host):
now = time.time()
svcEnable = "[%d] ENABLE_HOST_SVC_NOTIFICATIONS;%s" % (now,host)
svcDisable = "[%d] DISABLE_HOST_SVC_NOTIFICATIONS;%s" % (now,host)
hostEnable = "[%d] ENABLE_HOST_NOTIFICATIONS;%s" % (now,host)
hostDisable = "[%d] DISABLE_HOST_NOTIFICATIONS;%s" % (now,host)
if(action == "enable"):
svcStatus = svcEnable
hostStatus = hostEnable
print("[+] Pushing %s") % svcStatus
changeNotif(svcStatus)
print("[+] Pushing %s") % hostStatus
changeNotif(hostStatus)
elif(action == "disable"):
svcStatus = svcDisable
hostStatus = hostDisable
print("[+] Pushing %s") % svcStatus
changeNotif(svcStatus)
print("[+] Pushing %s") % hostStatus
changeNotif(hostStatus)
else:
print("[+] You must pass either 'enable' or 'disable' to command!")
sys.exit(0)
def openList(hostList):
fo = open(hostList, "r")
for line in fo.readlines():
motive(action, line)
openList(hostList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment