コード例 #1
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)
コード例 #2
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
コード例 #3
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()