ElastAlert2 emails alerts not sending after first couple of triggers - python-3.x

Below are my rule configs.
The problem is I am unable to receive emails after the first one or two emails.
Elastalert2 is running and its prints match found but don't send an alert except first alert when I started running the rule.
Last email I received was 19 hours ago and no emails after that although matches are found and elasrtalert2 rule is running constantly.
es_host: localhost
es_port: 9200
# Rule name, must be unique
name: Platform aggrigation rule prod Oct13
type: any
index: new-logstash*
aggregation:
schedule: '0 */12 * * *'
filter:
- term:
loglevel.keyword: "ERROR"
- terms:
servicename.keyword: ["postoffice", "pqrs"]
# - query:
# query_string:
# query: "message: enrolled"
# (Required)
# The alert is use when a match is found
alert:
- "email"
from_addr: "devtest#abc.com"
# (required, email specific)
# a list of email addresses to send alerts to
email:
#- "aamir.xyz#abc.net"
- "team#abc.net"
email_format: html
smtp_host: "mail.abc.com"
#smtp_host: "smtp.gmail.com"
smtp_port: 587 #for google email addresses
smtp_ssl: false
smtp_auth_file: "smtp_auth_file.yaml"
alert_subject: "Error Alert"
alert_text_type: alert_text_only
alert_text_args: ["loglevel","host.hostname","logtime","messageDetails", "servicename"]
alert_text: <html>

Related

RASA 2.8 - Final custom action in rules are not run

I'm trying to setup a bot that takes three inputs, two from buttons, and one from text. Currently, I'm able to pass in all of the required input. However, when it comes time for the final action, the bot does not seem to know what to do, and returns either a greeting or a message that it does not understand me. Is there anything wrong with my rules or domain files?
rule.yml
version: "2.0"
rules:
- rule: Activate conv_get_job_status
steps:
- intent: get_job_query
- action: action_populate_user_bot_info
- action: job_type_selection #this creates a list of buttons for job type selection
- action: job_type_input #job type form, to set job_type slot
- active_loop: job_type_input
- rule: Submit conv_get_job_status
condition:
- active_loop: job_type_input
- active_loop: job_name_and_number_input
steps:
- action: job_type_input
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: job_name_selection #this creates a list of buttons for job name selection
- action: job_name_and_number_input #job name and number form, to set job_name and job number slots
- active_loop: job_name_and_number_input
- action: job_name_and_number_input
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: action_return_job_status #various utterances, currently not called.
testjob_domain.yml
version: '2.0'
entities:
- job_type
- job_name
- job_number
intents:
- get_job_query
actions:
- action_reset_job_type_input
- job_number_query
- utter_ask_job_number
- utter_ask_job_name
- utter_ask_job_type
- action_return_job_status
- job_name_selection
- get_job_status
- action_reset_get_job_status
- job_type_selection
- action_reset_job_name_and_number_input
responses:
utter_ask_job_type:
- text: Select job type
utter_ask_job_name:
- text: Select job name
utter_ask_job_number:
- text: Enter job number
slots:
execute_action:
type: text
job_type:
type: text
job_name:
type: text
job_number:
type: text
forms:
job_type_input:
job_type:
- type: from_text
intent_name: None
job_name_and_number_input:
job_name:
- type: from_text
intent_name: None
job_number:
- type: from_text
intent_name: None
The code for action_return_job_status:
from .action_utils import *
class ActionReturnJobStatus(Action):
def name(self):
return "action_return_job_status"
def run(self, dispatcher, tracker, domain):
logger.info("Action - action_return_job_status")
logger.info("execute_action_slot: "+str(tracker.slots['execute_action']))
record_bot_event(tracker, dispatcher, 'new_session', auth_critical=authorization_critical)
# set auth_critical=True to skip action code execution
if not verifyBAMToken(tracker, dispatcher, auth_critical=authorization_critical):
return
logger.info("RUNNING GET ACTION")#I would expect to see either this in the logs or the utterances. Neither happens
dispatcher.utter_message("RUNNING GET ACTION")
return [SlotSet('latest_faq_question', None), SlotSet('latest_application_name', None)]

ICMP - how to fix "no response found" while keeping different data in request - reply

The problem: how to fix this warning: [ Expert Info (Warning/Sequence): No response seen to ICMP request]
The story: I'm playing with scapy. I have two tools: A is the sender ( which sends a echo-request ) and B is the recipient ( which sends a echo-reply AFTER it sniffs a echo-request ). The code of A:
....
pinger = IP(dst=x.x.x.x)/ICMP(id=0x7ccb, seq=1)/text
....
The code of B:
.....
sniff(filter=f"src host x.x.x.x and dst host x.x.x.x and icmp",
iface="XX", count=1)
send(IP(dst=x.x.x.x)/ICMP(type="echo-reply", id=0x7ccb, seq=1)/textback)
....
The result:
enter image description here
It appears that if the payloads ( text of A and textback of B ) are the same, this warning does not get displayed. However, for my goal, the text shall be different. So, how do I get rid of this warning while keeping both payloads not the same?
The data received in the echo message must be returned in the echo reply message.

Is there any way to reduce this code of prometheus alert expressions? I have multiple similar expression only the source instance is different

Suppose I am getting the metrics from a service in event_processing_bucket tag
where instance are like source=ONE, source=TWO, source=THREE ...... TEN
Currently I am using the following way to get the alert, but here I have written a separate expression just because i have to get data for every single source.
Is there any way to reduce this duplicate code. so that i could write only one alert rule and it will alert for all separately based on its respective value
Here are the prometheus alert expressions,
- alert: ONE_SLA_GREATER_THAN_5DAYS
expr: sum(rate(event_processing_bucket{source="ONE"}[1m])) > 5
for: 1m
labels:
severity: warning
team: mySlackChannel
annotations:
description: ONE_SLA is GREATER_THAN_5DAYS
summary: ONE_SLA is GREATER_THAN_5DAYS
- alert: TWO_SLA_GREATER_THAN_5DAYS
expr: sum(rate(event_processing_bucket{source="TWO"}[1m])) > 5
for: 1m
labels:
severity: warning
team: mySlackChannel
annotations:
description: TWO_SLA is GREATER_THAN_5DAYS
summary: TWO_SLA is GREATER_THAN_5DAYS
.
.
.
- alert: TEN_SLA_GREATER_THAN_5DAYS
expr: sum(rate(event_processing_bucket{source="TEN"}[1m])) > 5
for: 1m
labels:
severity: warning
team: mySlackChannel
annotations:
description: TEN_SLA is GREATER_THAN_5DAYS
summary: TEN_SLA is GREATER_THAN_5DAYS
Please guide me to write single expression code if possible. if not please specify.
Thanks in advance!!
One way is to group by
histogram_quantile(0.95, sum(increase(event_bucket[5m])) by (le, source)) > 5
later result values can be used to trigger those many alerts

Artillery.io: How to generate test report for each Scenario?

Artillery: How to run the scenarios sequentially and also display the results of each scenario in the same file?
I'm currently writing nodejs test with artillery.io to compare performance between two endpoints that I implemented. I defined two scenarios and I would like to get the result of each in a same report file.
The execution of the tests is not sequential, it means that at the end of the test I have a result already combined and impossible to know the performance of each one but for all.
config:
target: "http://localhost:8080/api/v1"
plugins:
expect: {}
metrics-by-endpoint: {}
phases:
- duration: 60
arrivalRate: 2
environments:
dev:
target: "https://backend.com/api/v1"
phases:
- duration: 60
arrivalRate: 2
scenarios:
- name: "Nashhorn"
flow:
- post:
url: "/casting/nashhorn"
auth:
user: user1
pass: user1
json:
body:
fromFile: "./casting-dataset-01-as-input.json"
options:
filename: "casting_dataset"
conentType: "application/json"
expect:
statusCode: 200
capture:
regexp: '[^]*'
as: 'result'
- log: 'result= {{result}}'
- name: "Nodejs"
flow:
- post:
url: "/casting/nodejs"
auth:
user: user1
pass: user1
json:
body:
fromFile: "./casting-dataset-01-as-input.json"
options:
filename: "casting_dataset"
conentType: "application/json"
expect:
statusCode: 200
capture:
regexp: '[^]*'
as: 'result'
- log: 'result= {{result}}'
How to run the scenarios sequentially and also display the results of each scenario in the same file?
Thank you in advance for your answers
I think you miss the param weight, this param defines de probability to execute the scenario. if in you first scenario put a weight of 1 and in the second put the same value, both will have the same probability to been execute (50%).
If you put in the first scenario a weight of 3 and in the second one a weight of 1, the second scenario will have a 25% probability of execution while the first one will have a 75% probability of being executed.
This combined with the arrivalRate parameter and setting the value of rampTo to 2, will cause 2 scenarios to be executed every second, in which if you set a weight of 1 to the two scenarios, they will be executed at the same time.
Look down for scenario weights in the documentation
scenarios:
- flow:
- log: Scenario for GET requests
- get:
url: /v1/url_test_1
name: Scenario for GET requests
weight: 1
- flow:
- log: Scenario for POST requets
- post:
json: {}
url: /v1/url_test_2
name: Scenario for POST
weight: 1
I hope this helps you.
To my knowledge, there isn't a good way to do this with the existing the artillery logic.
using this test script:
scenarios:
- name: "test 1"
flow:
- post:
url: "/postman-echo.com/get?test=123"
weight: 1
- name: "test 2"
flow:
- post:
url: "/postman-echo.com/get?test=123"
weight: 1
... etc...
Started phase 0 (equal weight), duration: 1s # 13:21:54(-0500) 2021-01-06
Report # 13:21:55(-0500) 2021-01-06
Elapsed time: 1 second
Scenarios launched: 20
Scenarios completed: 20
Requests completed: 20
Mean response/sec: 14.18
Response time (msec):
min: 117.2
max: 146.1
median: 128.6
p95: 144.5
p99: 146.1
Codes:
404: 20
All virtual users finished
Summary report # 13:21:55(-0500) 2021-01-06
Scenarios launched: 20
Scenarios completed: 20
Requests completed: 20
Mean response/sec: 14.18
Response time (msec):
min: 117.2
max: 146.1
median: 128.6
p95: 144.5
p99: 146.1
Scenario counts:
test 7: 4 (20%)
test 5: 2 (10%)
test 3: 1 (5%)
test 1: 4 (20%)
test 9: 2 (10%)
test 8: 3 (15%)
test 10: 2 (10%)
test 4: 1 (5%)
test 6: 1 (5%)
Codes:
404: 20
So basically you can see that they are weighted equally, but are not running equally. So I think there needs to be something added to the code itself for artillery. Happy to be wrong here.
You can use the per endpoint metrics plugin to give you the results per endpoint instead of aggregated.
https://artillery.io/docs/guides/plugins/plugin-metrics-by-endpoint.html
I see you already have this in your config, but it cannot be working if it is not giving you what you need. Did you install it as well as add to config?
npm install artillery-plugin-metrics-by-endpoint
In terms of running sequentially, I'm not sure why you would want to, but assuming you do, you just need to define each POST as part of the same Scenario instead of 2 different scenarios. That way the second step will only execute after the first step has responded. I believe the plugin is per endpoint, not per scenario so will still give you the report you want.

Unable to Parse Email in Python

I have set of .msg files stored in E:/ drive that I have to read and extract some information from it.
For that i am using the below code in Python 3.6.
from email.parser import Parser
with open("E:\Downloads\Test1.msg",encoding="ISO-8859-1") as fp:
headers = Parser().parse(fp)
print('To: %s' % headers['To'])
print('From: %s' % headers['From'])
print('Subject: %s' % headers['subject'])
In the output I am getting as below.
To: None
From: None
Subject: None
Process finished with exit code 0
I am not getting the actual values in To, FROM and subject fields.
Any thoughts why it is not printing the actual values?
My sample .msg file looks like below.
From: Bournemouth.wmt#gmail.com
To: Francis.dell#gmail.com
Subject: orderid: ord1234, circtid: cr1234
Charges:
Annual Charge - 10
Excess Charges - 5
From this message I am trying to extract order id, circuit id from subject and charges from mail body.
Output1:
Thanks
This is the body of the file that you posted on pastebin for us.
From: ratankumar.shivratri#TechM.com <ratankumar.shivratri#TechM.com>
Sent: Thursday, January 4, 2018 11:58 AM
To: Ratankumar Shivratri
Subject: Cct Id: ONE211, eCo order No: 1CTRP
Charges:
Annual rental - 2,125.00
Maintenance charge - 0.00
Regards
Ratan.
I've been able to obtain data from the headers using the following code.
>>> from email.parser import Parser
>>> p = Parser()
>>> msg = p.parse(open('ratan.msg'))
>>> msg['To']
'Ratankumar Shivratri'
>>> msg['From']
'ratankumar.shivratri#TechM.com <ratankumar.shivratri#TechM.com>'
>>> msg['Subject']
'Cct Id: ONE211, eCo order No: 1CTRP\n '
So that much works.
The next problem I foresee is that the format of the subject headers seems to be inconsistent across messages. For instance, in the message in your question, the subject header is 'orderid: ord1234, circtid: cr1234' but in this message it's 'Cct Id: ONE211, eCo order No: 1CTRP'. You want to be able to recover 'order id, circuit id' from messages but these items don't appear in every message.
If they did you could probably ferret them out with a regex.

Resources