5
5
from utilities import *
6
6
7
7
8
- # class Alerts:
9
- # def __init__(self):
10
- # self.logger_sub_path = "/logger"
11
- #
12
- # @staticmethod
13
- # def get_board_by_id(id):
14
- # url = "https://api.trello.com/1/boards/" + id + "/"
15
- # querystring = {"actions": "all", "boardStars": "none", "cards": "none", "card_pluginData": "false",
16
- # "checklists": "none",
17
- # "customFields": "false",
18
- # "fields": "name,desc,descData,closed,idOrganization,pinned,url,shortUrl,prefs,labelNames",
19
- # "lists": "open", "members": "none", "memberships": "none", "membersInvited": "none",
20
- # "membersInvited_fields": "all", "pluginData": "false", "organization": "false",
21
- # "organization_pluginData": "false", "myPrefs": "false",
22
- # "tags": "false", "key": TRELLO_API_KEY, "token": TRELLO_SERVER_TOKEN}
23
- # requests.request("GET", url, params=querystring)
24
- #
25
- # @staticmethod
26
- # def get_lists_on_a_board(board_id):
27
- # url = "https://api.trello.com/1/boards/" + board_id + "/lists"
28
- # querystring = {"key": TRELLO_API_KEY, "token": TRELLO_SERVER_TOKEN}
29
- # requests.request("GET", url, params=querystring)
30
- #
31
- # @staticmethod
32
- # def get_labels_on_a_board(board_id):
33
- # url = "https://api.trello.com/1/boards/" + board_id + "/labels"
34
- # querystring = {"key": TRELLO_API_KEY, "token": TRELLO_SERVER_TOKEN}
35
- # requests.request("GET", url, params=querystring)
36
- #
37
- # @staticmethod
38
- # def create_a_new_card_with_alert_message(list_id, labels_id, alert_message):
39
- # url = "https://api.trello.com/1/cards"
40
- # name = time.strftime("%Y%m%d") + "_" + time.strftime("%H%M%S") + "_" + "Phoenix_Down_Script_ALERT"
41
- # position = "top"
42
- # querystring = {"key": TRELLO_API_KEY, "token": TRELLO_SERVER_TOKEN, "name": name, "desc": alert_message,
43
- # "pos": position, "idList": list_id, "idLabels": labels_id}
44
- # requests.request("POST", url, params=querystring)
45
- #
46
- # @staticmethod
47
- # def parse_logger_file_and_create_alert_mail_message(logger_file_to_parse):
48
- # warnings_count = 0
49
- # errors_count = 0
50
- # script_starting_fail = True
51
- # script_ending_fail = True
52
- # # opens the file for reading only
53
- # file = open(logger_file_to_parse, "r")
54
- # for line in file.readlines():
55
- # if "[WARNING]" in line:
56
- # warnings_count += 1
57
- # if "[ERROR]" in line:
58
- # errors_count += 1
59
- # if PD_SCRIPT_STARTING_MESSAGE in line:
60
- # script_starting_fail = False
61
- # if PD_SCRIPT_ENDING_MESSAGE in line:
62
- # script_ending_fail = False
63
- # file.close()
64
- # if script_starting_fail or script_ending_fail:
65
- # alert_mail_message = "FATAL ERROR : There was a fatal error during the execution of the script, " \
66
- # "which could not be completed. Please check that the script is working properly !"
67
- # else:
68
- # alert_mail_message = "During the last execution of Phoenix Down Script, " \
69
- # "the logger returned " + str(warnings_count) + \
70
- # " warning messages, and " \
71
- # + str(errors_count) + " error messages. " \
72
- # "Please check that the script is working properly !"
73
- # return alert_mail_message, script_starting_fail, script_ending_fail, warnings_count, errors_count
74
- #
75
- # def run_script(self):
76
- # logger_file_to_parse = get_the_latest_file_in_a_folder(PD_SCRIPT_ROOT_LOGS_PATH + self.logger_sub_path )
77
- #
78
- # callback_alert_infos = self.parse_logger_file_and_create_alert_mail_message(logger_file_to_parse)
79
- # if callback_alert_infos[1] or callback_alert_infos[2] \
80
- # or callback_alert_infos[3] > 0 or callback_alert_infos[4] > 0:
81
- # self.create_a_new_card_with_alert_message(TRELLO_ALERT_BOARD_ALERT_LIST_ID,
82
- # TRELLO_ALERT_URGENT_CUSTOM_LABEL_ID, callback_alert_infos[0])
83
- # self.create_a_new_card_with_alert_message(TRELLO_MBL_BOARD_ADMIN_LIST_ID,
84
- # TRELLO_MBL_URGENT_CUSTOM_LABEL_ID, callback_alert_infos[0])
8
+ class Alerts :
9
+ def __init__ (self ):
10
+ self .logger_sub_path = "/logger"
11
+
12
+ @staticmethod
13
+ def get_board_by_id (id ):
14
+ url = "https://api.trello.com/1/boards/" + id + "/"
15
+ querystring = {"actions" : "all" , "boardStars" : "none" , "cards" : "none" , "card_pluginData" : "false" ,
16
+ "checklists" : "none" ,
17
+ "customFields" : "false" ,
18
+ "fields" : "name,desc,descData,closed,idOrganization,pinned,url,shortUrl,prefs,labelNames" ,
19
+ "lists" : "open" , "members" : "none" , "memberships" : "none" , "membersInvited" : "none" ,
20
+ "membersInvited_fields" : "all" , "pluginData" : "false" , "organization" : "false" ,
21
+ "organization_pluginData" : "false" , "myPrefs" : "false" ,
22
+ "tags" : "false" , "key" : TRELLO_API_KEY , "token" : TRELLO_SERVER_TOKEN }
23
+ requests .request ("GET" , url , params = querystring )
24
+
25
+ @staticmethod
26
+ def get_lists_on_a_board (board_id ):
27
+ url = "https://api.trello.com/1/boards/" + board_id + "/lists"
28
+ querystring = {"key" : TRELLO_API_KEY , "token" : TRELLO_SERVER_TOKEN }
29
+ requests .request ("GET" , url , params = querystring )
30
+
31
+ @staticmethod
32
+ def get_labels_on_a_board (board_id ):
33
+ url = "https://api.trello.com/1/boards/" + board_id + "/labels"
34
+ querystring = {"key" : TRELLO_API_KEY , "token" : TRELLO_SERVER_TOKEN }
35
+ requests .request ("GET" , url , params = querystring )
36
+
37
+ @staticmethod
38
+ def create_a_new_card_with_alert_message (list_id , labels_id , alert_message ):
39
+ url = "https://api.trello.com/1/cards"
40
+ name = time .strftime ("%Y%m%d" ) + "_" + time .strftime ("%H%M%S" ) + "_" + "Phoenix_Down_Script_ALERT"
41
+ position = "top"
42
+ querystring = {"key" : TRELLO_API_KEY , "token" : TRELLO_SERVER_TOKEN , "name" : name , "desc" : alert_message ,
43
+ "pos" : position , "idList" : list_id , "idLabels" : labels_id }
44
+ requests .request ("POST" , url , params = querystring )
45
+
46
+ @staticmethod
47
+ def parse_logger_file_and_create_alert_mail_message (logger_file_to_parse ):
48
+ warnings_count = 0
49
+ errors_count = 0
50
+ script_starting_fail = True
51
+ script_ending_fail = True
52
+ # opens the file for reading only
53
+ file = open (logger_file_to_parse , "r" )
54
+ for line in file .readlines ():
55
+ if "[WARNING]" in line :
56
+ warnings_count += 1
57
+ if "[ERROR]" in line :
58
+ errors_count += 1
59
+ if SLIMER_SCRIPT_STARTING_MESSAGE in line :
60
+ script_starting_fail = False
61
+ if SLIMER_SCRIPT_ENDING_MESSAGE in line :
62
+ script_ending_fail = False
63
+ file .close ()
64
+ if script_starting_fail or script_ending_fail :
65
+ alert_mail_message = "FATAL ERROR : There was a fatal error during the execution of the script, " \
66
+ "which could not be completed. Please check that the script is working properly !"
67
+ else :
68
+ alert_mail_message = "During the last execution of Phoenix Down Script, " \
69
+ "the logger returned " + str (warnings_count ) + \
70
+ " warning messages, and " \
71
+ + str (errors_count ) + " error messages. " \
72
+ "Please check that the script is working properly !"
73
+ return alert_mail_message , script_starting_fail , script_ending_fail , warnings_count , errors_count
74
+
75
+ def run_script (self ):
76
+ logger_file_to_parse = get_the_latest_file_in_a_folder (SLIMER_SCRIPT_ROOT_LOGGER_PATH )
77
+
78
+ callback_alert_infos = self .parse_logger_file_and_create_alert_mail_message (logger_file_to_parse )
79
+ if callback_alert_infos [1 ] or callback_alert_infos [2 ] \
80
+ or callback_alert_infos [3 ] > 0 or callback_alert_infos [4 ] > 0 :
81
+ self .create_a_new_card_with_alert_message (TRELLO_ALERT_BOARD_ALERT_LIST_ID ,
82
+ TRELLO_ALERT_URGENT_CUSTOM_LABEL_ID , callback_alert_infos [0 ])
83
+ self .create_a_new_card_with_alert_message (TRELLO_MBL_BOARD_ADMIN_LIST_ID ,
84
+ TRELLO_MBL_URGENT_CUSTOM_LABEL_ID , callback_alert_infos [0 ])
0 commit comments