Пример #1
0
def disable_alert(commandParameters, channel):
	if(len(commandParameters) > 1):
		Splunk.disableAlert(commandParameters[0], int(commandParameters[1]))
		HipChat.postNotification("{} disabled for {} minutes".format(commandParameters[0], commandParameters[1]), channel)
	else:
		Splunk.disableAlert(commandParameters[0])
		HipChat.postNotification("{} disabled".format(commandParameters[0]), channel)
Пример #2
0
def list_apps(commandParameters, channel):
	if(len(commandParameters) > 0):
		results = Splunk.listAppNames(commandParameters[0])
	else:
		results = Splunk.listAppNames()
	results = eval(results)
	HipChat.postNotification(Util.formatArray(results), channel)
Пример #3
0
def list_saved_searches(commandParameters, channel):
	"""  """
	if(len(commandParameters) > 0):
		results = Splunk.listSavedSearches(commandParameters[0])
	else:
		results = Splunk.listSavedSearches()
	HipChat.postNotification(str(results), channel)
Пример #4
0
def list_dashboards(commandParameters, channel):
	if(len(commandParameters) > 1):
		results = Splunk.listDashboardNames(commandParameters[0], commandParameters[1])
	else:
		results = Splunk.listDashboardNames(commandParameters[0])
	results = eval(results)
	HipChat.postNotification(Util.formatArray(results), channel)
Пример #5
0
def list_disabled_alerts(commandParameters, channel):
	if(len(commandParameters) > 0):
		results = Splunk.listDisabledAlerts(commandParameters[0])
	else:
		results = Splunk.listDisabledAlerts()
	results = eval(results)
	HipChat.postNotification(Util.formatArray(results), channel)
Пример #6
0
def connect_to(commandParameters, channel):
	global enviroment
	
	if commandParameters[0].upper() == "ITEST":
		enviroment = commandParameters[0].upper()
		BASE_URL = "https://splunk-itest.ercot.com:8089"
		USERNAME = os.environ.get('SPLUNK_USERNAME')
		PASSWORD = os.environ.get('SPLUNK_PASSWORD')
		
		Splunk.connect(BASE_URL, USERNAME, PASSWORD)
		HipChat.postNotification("Connected to ITest", channel)
		
	elif commandParameters[0].upper() == "LOCAL":
		enviroment = commandParameters[0].upper()
		BASE_URL = "https://localhost:8089"
		USERNAME = os.environ.get('SPLUNK_LOCAL_USERNAME')
		PASSWORD = os.environ.get('SPLUNK_LOCAL_PASSWORD')
		
		Splunk.connect(BASE_URL, USERNAME, PASSWORD)
		HipChat.postNotification("Connected to Local", channel)
Пример #7
0
def listDisabledAlerts(params):
	if len(params) > 0:
		return splunk.listDisabledAlerts(params[0])
	else:
		return splunk.listDisabledAlerts()
Пример #8
0
def listDashboardNames(params):
	if len(params) == 2:
		return splunk.listDashboardNames(params[0],params[1])
	else:
		return splunk.listDashboardNames(params[0])
Пример #9
0
def get_dashboard(commandParameters, channel):
	HipChat.postNotification("Getting dashboard {} from {}".format(commandParameters[1], commandParameters[0]), channel)
	Splunk.getDashboardPdf(commandParameters[0], commandParameters[1])
	pdfName = commandParameters[0] + "_" + commandParameters[1]
	pdfPath = 'pdf_files/{}.pdf'.format(pdfName)
	HipChat.postFile(pdfPath, channel)
Пример #10
0
def run_search(commandParameters, channel):
	results = Splunk.runSearch(commandParameters[0])
	results = eval(results)
	table = Util.formatResultsAsHTMLTable(results)
	HipChat.postNotification(table, channel, format = 'html')
Пример #11
0
def listDashboardInputs(params):
	return splunk.listDashboardInputs(params[0],params[1])		
Пример #12
0
#!/usr/bin/python
from http.server import BaseHTTPRequestHandler,HTTPServer
from urllib.parse import urlparse
import RESTSplunkMethods as splunk
import wrapper
import helper
import os

PORT_NUMBER = 8080
baseurl = 'https://localhost:8089'
username = os.environ.get('SPLUNK_USERNAME_LOCAL')
password = os.environ.get('SPLUNK_PASSWORD_LOCAL')

splunk.connect(baseurl, username, password)

def toCamelCase(str):
	str = str.lower()
	components = str.split(' ')
	# Capitalize the first letter of each component except the first one
	# with the 'title' method and join them together.
	return components[0] + ''.join(x.title() for x in components[1:])

# This class will handle any incoming request from the browser 
class myHandler(BaseHTTPRequestHandler):
	
	# Handler for POST requests
	def do_POST(self):
		contentLength = int(self.headers['Content-Length']) # <--- Gets the size of data
		postBody = (self.rfile.read(contentLength)).decode('utf-8') # <--- Gets the data itself
		
		# Extract the command and the parameters from the postBody
Пример #13
0
def run_saved_search(commandParameters, channel):
	results = Splunk.runSavedSearch(commandParameters[0])
	HipChat.postNotification(str(results), channel)
Пример #14
0
def getDashboardPdf(params):
	if len(params) == 3:
		return splunk.getDashboardPdf(params[0],params[1], params[2])
	else:
		return splunk.getDashboardPdf(params[0],params[1])
Пример #15
0
def runSearch(params):
	return splunk.runSearch(params[0])
Пример #16
0
def getReportPdf(params):
	return splunk.getReportPdf(params[0])
Пример #17
0
def enableAlert(params):
	return splunk.enableAlert(params[0])
Пример #18
0
def listSavedSearches(params):
	if len(params) > 0:
		return splunk.listSavedSearches(params[0])
	else:
		return splunk.listSavedSearches()
Пример #19
0
def disableAlert(params):
	if len(params) == 2:
		return splunk.disableAlert(params[0],params[1])
	else:
		return splunk.disableAlert(params[0])
Пример #20
0
def getSearchPdf(params):
	return splunk.getSearchPdf(params[0])
Пример #21
0
def enable_alert(commandParameters, channel):
	Splunk.enableAlert(commandParameters[0])
	HipChat.postNotification("{} enabled".format(commandParameters[0]), channel)
Пример #22
0
def rescheduleAlert(params):
	return splunk.rescheduleAlert(params[0],params[1])
Пример #23
0
def listAppNames(params):
	if len(params) > 0:
		return splunk.listAppNames(params[0])
	else:
		return splunk.listAppNames()
Пример #24
0
SPLUNK_BASE_URL = "https://splunk-itest.ercot.com:8089"
USERNAME = os.environ.get('SPLUNK_USERNAME')
PASSWORD = os.environ.get('SPLUNK_PASSWORD')

#the room of hipchat that is watched is a variable set in SimpleHipChat

#constants
RTM_READ_DELAY = 5 #second delay between reading from RTM

if __name__ == "__main__":
	HipChat.connect(HIPCHAT_BOT_TOKEN, HIPCHAT_HOST)
	#Trigger is the character that triggers command parsing
	trigger = '!'
	print("\nSplunkBot connected to HipChat")
	
	Splunk.connect(SPLUNK_BASE_URL, USERNAME, PASSWORD)
	
	while True:
		try:
			#return messages from chat that start with the trigger
			command, channel = Command.parseBotCommands(HipChat.getEvents(), trigger)
			
			if command:
				try:
					Splunk.checkConnection()
					print(command)
					Command.handleCommand(command, channel)
				except Exception:
					HipChat.postNotification("Error Running Command: {}".format(command), channel)
					print("\nError Running Command: {}\n".format(command))
					traceback.print_exc()