mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-23 06:37:15 +00:00
Fixed e-mail notificatins for sets and regexes
This commit is contained in:
parent
b6fcf51309
commit
29608ab29b
4 changed files with 31 additions and 25 deletions
|
@ -90,17 +90,14 @@ if __name__ == "__main__":
|
||||||
if matched is not None: #there is a match
|
if matched is not None: #there is a match
|
||||||
print('regex matched {}'.format(regex_str))
|
print('regex matched {}'.format(regex_str))
|
||||||
matched = matched.group(0)
|
matched = matched.group(0)
|
||||||
|
regex_str_complete = "/" + regex_str + "/"
|
||||||
# Add in Regex track set only if term is not in the blacklist
|
# Add in Regex track set only if term is not in the blacklist
|
||||||
if matched not in server_term.smembers(BlackListTermsSet_Name):
|
if regex_str_complete not in server_term.smembers(BlackListTermsSet_Name):
|
||||||
|
|
||||||
# Send a notification only when the member is in the set
|
# Send a notification only when the member is in the set
|
||||||
if matched in server_term.smembers(TrackedTermsNotificationEnabled_Name):
|
if regex_str_complete in server_term.smembers(TrackedTermsNotificationEnabled_Name):
|
||||||
|
|
||||||
# Send to every associated email adress
|
# Send to every associated email adress
|
||||||
for email in server_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + matched):
|
for email in server_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + regex_str_complete):
|
||||||
sendEmailNotification(email, matched)
|
sendEmailNotification(email, regex_str)
|
||||||
|
|
||||||
|
|
||||||
set_name = 'regex_' + dico_regexname_to_redis[regex_str]
|
set_name = 'regex_' + dico_regexname_to_redis[regex_str]
|
||||||
new_to_the_set = server_term.sadd(set_name, filename)
|
new_to_the_set = server_term.sadd(set_name, filename)
|
||||||
|
|
|
@ -75,7 +75,6 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
message = p.get_from_set()
|
message = p.get_from_set()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -103,13 +102,11 @@ if __name__ == "__main__":
|
||||||
for the_set, matchingNum in match_dico.items():
|
for the_set, matchingNum in match_dico.items():
|
||||||
eff_percent = float(matchingNum) / float((len(ast.literal_eval(the_set))-1)) * 100 #-1 bc if the percent matching
|
eff_percent = float(matchingNum) / float((len(ast.literal_eval(the_set))-1)) * 100 #-1 bc if the percent matching
|
||||||
if eff_percent >= dico_percent[the_set]:
|
if eff_percent >= dico_percent[the_set]:
|
||||||
|
|
||||||
# Send a notification only when the member is in the set
|
# Send a notification only when the member is in the set
|
||||||
if the_set in server_term.smembers(TrackedTermsNotificationEnabled_Name):
|
if dico_setname_to_redis[str(the_set)] in server_term.smembers(TrackedTermsNotificationEnabled_Name):
|
||||||
|
|
||||||
# Send to every associated email adress
|
# Send to every associated email adress
|
||||||
for email in server_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + the_set):
|
for email in server_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + dico_setname_to_redis[str(the_set)]):
|
||||||
sendEmailNotification(email, the_set)
|
sendEmailNotification(email, dico_setname_to_redis[str(the_set)])
|
||||||
|
|
||||||
print(the_set, "matched in", filename)
|
print(the_set, "matched in", filename)
|
||||||
set_name = 'set_' + dico_setname_to_redis[the_set]
|
set_name = 'set_' + dico_setname_to_redis[the_set]
|
||||||
|
|
|
@ -330,18 +330,17 @@ def terms_management_action():
|
||||||
if re.match(r"[^@]+@[^@]+\.[^@]+", email):
|
if re.match(r"[^@]+@[^@]+\.[^@]+", email):
|
||||||
validNotificationEmails.append(email)
|
validNotificationEmails.append(email)
|
||||||
|
|
||||||
# add all valid emails to the set
|
|
||||||
for email in validNotificationEmails:
|
|
||||||
r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + term.lower(), email)
|
|
||||||
|
|
||||||
# enable notifications by default
|
|
||||||
r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, term.lower())
|
|
||||||
|
|
||||||
# check if regex/set or simple term
|
# check if regex/set or simple term
|
||||||
#regex
|
#regex
|
||||||
if term.startswith('/') and term.endswith('/'):
|
if term.startswith('/') and term.endswith('/'):
|
||||||
r_serv_term.sadd(TrackedRegexSet_Name, term)
|
r_serv_term.sadd(TrackedRegexSet_Name, term)
|
||||||
r_serv_term.hset(TrackedRegexDate_Name, term, today_timestamp)
|
r_serv_term.hset(TrackedRegexDate_Name, term, today_timestamp)
|
||||||
|
# add all valid emails to the set
|
||||||
|
for email in validNotificationEmails:
|
||||||
|
r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + term, email)
|
||||||
|
# enable notifications by default
|
||||||
|
r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, term)
|
||||||
|
|
||||||
#set
|
#set
|
||||||
elif term.startswith('\\') and term.endswith('\\'):
|
elif term.startswith('\\') and term.endswith('\\'):
|
||||||
|
@ -355,11 +354,21 @@ def terms_management_action():
|
||||||
set_to_add = "\\" + tab_term[:-1] + ", [{}]]\\".format(match_percent)
|
set_to_add = "\\" + tab_term[:-1] + ", [{}]]\\".format(match_percent)
|
||||||
r_serv_term.sadd(TrackedSetSet_Name, set_to_add)
|
r_serv_term.sadd(TrackedSetSet_Name, set_to_add)
|
||||||
r_serv_term.hset(TrackedSetDate_Name, set_to_add, today_timestamp)
|
r_serv_term.hset(TrackedSetDate_Name, set_to_add, today_timestamp)
|
||||||
|
# add all valid emails to the set
|
||||||
|
for email in validNotificationEmails:
|
||||||
|
r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + set_to_add, email)
|
||||||
|
# enable notifications by default
|
||||||
|
r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, set_to_add)
|
||||||
|
|
||||||
#simple term
|
#simple term
|
||||||
else:
|
else:
|
||||||
r_serv_term.sadd(TrackedTermsSet_Name, term.lower())
|
r_serv_term.sadd(TrackedTermsSet_Name, term.lower())
|
||||||
r_serv_term.hset(TrackedTermsDate_Name, term.lower(), today_timestamp)
|
r_serv_term.hset(TrackedTermsDate_Name, term.lower(), today_timestamp)
|
||||||
|
# add all valid emails to the set
|
||||||
|
for email in validNotificationEmails:
|
||||||
|
r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + term.lower(), email)
|
||||||
|
# enable notifications by default
|
||||||
|
r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, term.lower())
|
||||||
|
|
||||||
elif action == "toggleEMailNotification":
|
elif action == "toggleEMailNotification":
|
||||||
# get the current state
|
# get the current state
|
||||||
|
|
|
@ -129,7 +129,7 @@
|
||||||
<button class="btn-link btn-interaction" data-toggle="tooltip" data-placement="left" title="Remove this term" data-content="{{ set }}" data-section="followTerm" data-action="delete"><span class="glyphicon glyphicon-trash"></span></button>
|
<button class="btn-link btn-interaction" data-toggle="tooltip" data-placement="left" title="Remove this term" data-content="{{ set }}" data-section="followTerm" data-action="delete"><span class="glyphicon glyphicon-trash"></span></button>
|
||||||
<input id="checkBoxEMailAlerts" type="checkbox" title="Toggle E-Mail notifications" class="btn-link btn-interaction" data-content="{{ set }}" data-section="followTerm" data-action="toggleEMailNotification" {% if notificationEnabledDict[set] %} checked {% endif %}>
|
<input id="checkBoxEMailAlerts" type="checkbox" title="Toggle E-Mail notifications" class="btn-link btn-interaction" data-content="{{ set }}" data-section="followTerm" data-action="toggleEMailNotification" {% if notificationEnabledDict[set] %} checked {% endif %}>
|
||||||
</p></td>
|
</p></td>
|
||||||
<td style="white-space:pre">{{ notificationEMailTermMapping[term] }}</td>
|
<td style="white-space:pre">{{ notificationEMailTermMapping[set] }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<!-- REGEX -->
|
<!-- REGEX -->
|
||||||
|
@ -146,7 +146,7 @@
|
||||||
<button class="btn-link btn-interaction" data-toggle="tooltip" data-placement="left" title="Remove this term" data-content="{{ regex }}" data-section="followTerm" data-action="delete"><span class="glyphicon glyphicon-trash"></span></button>
|
<button class="btn-link btn-interaction" data-toggle="tooltip" data-placement="left" title="Remove this term" data-content="{{ regex }}" data-section="followTerm" data-action="delete"><span class="glyphicon glyphicon-trash"></span></button>
|
||||||
<input id="checkBoxEMailAlerts" type="checkbox" title="Toggle E-Mail notifications" class="btn-link btn-interaction" data-content="{{ regex }}" data-section="followTerm" data-action="toggleEMailNotification" {% if notificationEnabledDict[regex] %} checked {% endif %}>
|
<input id="checkBoxEMailAlerts" type="checkbox" title="Toggle E-Mail notifications" class="btn-link btn-interaction" data-content="{{ regex }}" data-section="followTerm" data-action="toggleEMailNotification" {% if notificationEnabledDict[regex] %} checked {% endif %}>
|
||||||
</p></td>
|
</p></td>
|
||||||
<td style="white-space:pre">{{ notificationEMailTermMapping[term] }}</td>
|
<td style="white-space:pre">{{ notificationEMailTermMapping[regex] }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<!-- Normal term -->
|
<!-- Normal term -->
|
||||||
|
@ -408,3 +408,6 @@ function perform_operation(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue