-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.py
More file actions
91 lines (73 loc) · 2.58 KB
/
Copy pathbot.py
File metadata and controls
91 lines (73 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
########################################################################################
#
# bot.py
#
# The main program file of the serverless chatbot hackathon contest
# Does self-healing and allows users to query Github Enterprise (GHE) statuses
#
#########################################################################################
import boto3
import logging
import urllib2
import json
import ghe.ghe_command
import aws.self_healing
import config
#setup simple logging for INFO
log = logging.getLogger()
log.setLevel(logging.DEBUG)
# shows the help page
def show_help_and_exit():
return """
```
help - Print this help page
ghe orgs - Lists orgs using github enterprise
ghe users - List github enterprise users
ghe repos - List github enterprise reposes
ghe license - Show github enterprise license status
ghe monitor cpu [1d,1w,1mon] - Show the cpu monitor graph of github enterprise servers
ghe monitor memory [1d,1w,1mon] - Show the memory monitor graph of github enterprise servers
```
"""
# Our main entry point
def lambda_handler(event, context):
#log.debug(event)
bot_event = event
trigger_word = bot_event['trigger_word']
raw_text = bot_event['text']
raw_args = raw_text.replace(trigger_word, '').strip()
args = raw_args.split()
log.debug("[lambda_handler] args:{0}".format(args))
if len(args) >= 1:
feature = args[0]
command = None
if len(args) >= 2:
command = args[1]
options = ''
if len(args) >= 3:
options = args[2:]
log.debug("[lambda_handler] feature:'{0}' command:'{1}' options:'{2}'".format(
feature, command, options))
log.debug ('feature: ' + str(feature))
if (feature == 'help'):
log.debug("showing help and exiting..")
return {
'text' : show_help_and_exit()
}
if (feature == 'ghe'):
return {
'text' : ghe.ghe_command.ghe_main(command, options)
}
if (feature == 'PROBLEM'):
log.debug("Problem encountered")
return {
'text' : aws.self_healing.identify_problem(raw_args)
}
if (feature == 'RECOVERY'):
log.debug("Recover encountered")
return {
'text' : "I'm very happy that you're back up again :-)"
}
return {
'text': "{0}".format("Sorry, I didn't understand. Please use Wukong help")
}