Email alert based on monitors going down / coming back up - elastic-stack

I am fairly new to this but I need some help with my watcher setup. - I am using the X-Pack Watchers.
I have setup Heartbeat and I currently have 7 monitors.
i.e
monitor-01
monitor-02
etc.
I need help setting up my exact scenarios, I need help with 3 scenarios:
Scenario 1:
If monitor-01 goes offline, I want to send ONLY 1 email to "test#domain.com" with the body of: "Hello there, monitor-01 just went offline! Please check, thanks."
If monitor-02 goes offline, I want the exact same result as above.. I dont want multiple emails alerting me every second / minute if the monitor is down, I only want 1 email.
Scenario 2:
If monitor-01 or any my monitors are offline... Every 3 hours, I want a refresh email sent out (I would like the email body to contain how long the specific monitor is down for, i.e monitor down for 120hours 13 minutes). So, if 3 hours pass, I want to send an email to "test#domain.com" with the body of: "Hello there, this is a reminder email that monitor-01 is still offline! Please check, thanks."
Scenario 3:
If any of the monitors come back online, I want to send out an email to "test#domain.com" with the body of: "Hello there, great news! monitor-02 is back online. The monitor was down for 7hours 12 minutes. Thanks."
Can someone please assist? I looked everywhere and cannot find the correct syntax to create the above scenarios. These would be scenarios I feel could benefit other members of the community.
P.s, I currently have an advanced watch that I found in the forums but does not match my criteria. Here is the code for it:
{
"trigger": {
"schedule": {
"interval": "30s"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"heartbeat-*"
],
"rest_total_hits_as_int": true,
"body": {
"query": {
"bool": {
"must": {
"match": {
"monitor.status": "down"
}
},
"filter": {
"range": {
"#timestamp": {
"from": "now-50s"
}
}
}
}
},
"aggregations": {
"by_monitors": {
"terms": {
"field": "monitor.name"
}
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gt": 0
}
}
},
"actions": {
"email_admin": {
"email": {
"profile": "standard",
"from": "noreply#domain.com",
"to": [
"test#domain.com"
],
"subject": "Monitor is DOWN: {{ctx.payload.aggregations.by_monitors.buckets.0.key}}",
"body": {
"text": "Hello, there is a monitor offline currently. Please check..."
}
}
}
}
}
The above script I put together sends an email every 30 seconds if a monitor is down which is not what I want.
Here is what the email says when everything is put together:
Subject: Monitor is DOWN: [UAT] Test Website
Body: Hello, there is a monitor offline currently. Please check...
Can someone assist with my scenarios? I spent days on this already.. many hours gone in, not much to come out from it!
Thanks.

There are two things you could look into: throttling and acknowledging notifications
throttling: once an action is done (eg sending an email), don't do that action again for 3 hours
acknowledge: : in this case you need to call the API to say: "I did receive the notification that watcher01 has found an error, don't send any notifications about it again."

Related

POST request to JIRA REST API to create issue of type Minutes

my $create_issue_json = '{"fields": { "project": { "key": "ABC" }, "summary": "summary for version 1", "description": "Creating an issue via REST API", "issuetype": { "name": "Minutes" }}}';
$tx1 = $jira_ua->post($url2 => json => decode_json($create_issue_json));
my $res1 = $tx1->res->body;
I try to create a jira issue of type Minutes but POST expects some fields which are not available in the issue of type Minutes. The below is the response.
{"errorMessages":["Brands: Brands is required.","Detection: Detection is required."],"errors":{"versions":"Affects Version/s is required.","components":"Component/s is required."}}
I also tried to fetch the schema using createMeta api but don't find any useful info. The below is the response from createmeta.
{"maxResults":50,"startAt":0,"total":3,"isLast":true,"values":[
{
"self":"https://some_url.com/rest/api/2/issuetype/1",
"id":"1",
"description":"A problem which impairs or prevents the functions of the product.",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=25683&avatarType=issuetype",
"name":"Bug",
"subtask":false},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/12",
"id":"12",
"description":"An issue type to document minutes of meetings, telecons and the like",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=28180&avatarType=issuetype",
"name":"Minutes",
"subtask":false
},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/23",
"id":"23",
"description":"Used to split an existing issue of type \"Bug\"",
"iconUrl":"https://some_url.com:8443/images/icons/cmts_SubBug.gif",
"name":"Sub Bug",
"subtask":true
}
]
}
It looks like there Jira Admin has added these as manadatory fields for all the issuetypes which I came to know after speaking with him. He has now individual configuration for different issue types and am able to create minutes.

Get real-time comments from videos live Facebook-live-api

I'm setting up an endpoint to receive real-time comments from the live streaming video, I follow the steps in this document smoothly: https://developers.facebook.com/docs/graph-api/server-sent-events/endpoints/live-comments/.
There was one person who commented directly on my live streaming video twice, and I also got those 2 comments, but that person's "id" in 2 comments is different. Can anybody explain me on this, and is there any way to fix it.
var source = new EventSource(
'https://streaming-graph.facebook.com/{live-video-id}/live_comments?access_token={access_token}&comment_rate=one_per_two_seconds&fields=from{name,id},message');
source.onmessage = function(event) {
console.log(event.data);
};
response 1:
{ "from": { name: "Joe Commenter", "id": 126577551217199 },"message":
"I like it!" }
response 2:
{ "from": { name: "Joe Commenter", "id": 23567175551752 },"message":
"Great photo!" }
They're two different accounts, probably a bot building a profile to be used for spam later.

Multiple response in action on google dialogflow

How can i get multiple response on action on google console using dialogflow ?
i simulated on Action on google console but only two responses are showing on it
where as third response are not showing
here is my json response
{
"source": "webhook",
"data": {
"google": {
"is_ssml": true,
"permissions_request": null,
"expect_user_response": true
}
},
"messages": [
{
"type": 0,
"speech": "peter Got around 28 marks in maths. which is ranked 1 among 3 candidate in class 1"
},
{
"textToSpeech": "peter Got around 28 marks in maths. which is ranked 1 among 3 candidate in class 1",
"platform": "google",
"displayText": "peter Got around 28 marks in maths. which is ranked 1 among 3 candidate in class 1",
"type": "simple_response"
},
{
"textToSpeech": "Working",
"platform": "google",
"displayText": "Working",
"type": "simple_response"
},
{
"textToSpeech": "Working 2",
"platform": "google",
"displayText": "Working 2",
"type": "simple_response"
}
]
}
Here is my console output
any help regarding this is much appreciated
Thank you
Regards Saif
Only two simple responses will be accepted as a response. If you want more content you will need to consolidate your text into one of the two responses.
As you can see on the AoG Responses docs, it is specified as a requirement :
At most 2 chat bubbles per turn
So your third bubble won't display, as intended by Google.
As suggested in the previous answer from Nick, you need to consolidate your text and wrap everything in your 2 bubbles. In a simple response, you can line break by adding a \n where needed.
In a Basic Card however, you can access a limited subset of markdown, as stated in the docs link I provided, like that :
New line with a double space
**bold**
*italics*
Rich responses have the following requirements and optional properties that you can configure:
Supported on surfaces with the actions.capability.SCREEN_OUTPUT
capability.
The first item in a rich response must be a simple response.
At most two simple responses.
At most one basic card or StructuredResponse.
At most 8 suggestion chips. (you can add more than 8 also but you will get a warning not an error.)
Suggestion chips are not allowed in a FinalResponse
Linking out to the web from smart displays is currently not
supported.

Can't post node that requires a pre assigned value with services api

I have setup a content type with a subject field that has pre assigned values in a dropdown field.
I am using the services api to post new content from a polymer app.
When I POST to the api I send the field structure and value in json but get and error.
"406 (Not Acceptable : An illegal choice has been detected. Please contact the site administrator.)"
Even though the object I am sending matches one of the required values in the field.
Do I need to prefix the value with something? I assume I'm posting to the right place to get that response but don't know why it would accept anything other than the string value.
Here is what I sent to the api which is picked up by my Charles proxy.
{
"node": {
"type": "case",
"title": "my case",
"language": "und",
"field_subject": {
"und": {
"0": {
"value": "subject1"
}
}
},
"body": {
"und": {
"0": {
"value": "my details of subject"
}
}
}
}
}
And here is an example of what I have setup in my Drupal field
subject1| first
subject2| second
subject3| third
subject4| forth
For anyone else with the same problem, this subject is poorly documented, but the answer is simple, my subject did not need the value key despite devel suggesting thats how it would be formatted.
"field_subject": {
"und": [
"subject1"
]
}
I could also shorten my code with "und" being an array.

GitHub API: List a users teams within an organization

In GitHub when viewing my organization's user list I'm able to see how many teams a user is a member of.
Clicking on this count shows me which teams a user is in, putting me on the following page:
https://github.com/orgs/my-org/teams?query=%40username
However, I'm trying to achieve the same functionality via the GitHub API, but I've been unable to find an endpoint that lists what teams (within an organization) a user is currently a member of.
One workaround is to loop through all the teams in an organization and get their members list, but this can quickly go through my rate limit, so to be able to do this in one request would be useful.
You can do this with GraphQL API v4 filtering users in teams within an organization with userLogins :
{
organization(login: "my-org") {
teams(first: 100, userLogins: ["johndoe"]) {
totalCount
edges {
node {
name
description
}
}
}
}
}
which gives for instance :
{
"data": {
"organization": {
"teams": {
"totalCount": 2,
"edges": [
{
"node": {
"name": "Employees",
"description": "org employees"
}
},
{
"node": {
"name": "Developers",
"description": "active developers"
}
}
]
}
}
}
}
Source : platform.github.community forum
Unfortunately, GitHub does not yet provide a way to do this.
At the moment, like you suggested, you would have to loop through each team in the organization to get all members within each one, then you would need to loop through all users, and check if the users are members of those teams.
You can increase your rate limit if you use an API token, but the solution is still lousy if you have a large organization.
Heads up!
Providing an invalid/unknown "userLogin" sometimes results in all teams being returned.
Perhaps me doing something wrong, but I opened a ticket with GH about this, so lets see:
https://github.community/t/teams-userlogins-filter-is-not-working-as-expected/206251