-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation for Outbound Integration for prometehus #3
Comments
Hey @Alexvianet. Does Prometheus provide a silence API? They don't list one specifically here. But I did see this thread that mentions you might be able to do something like
So you could turn that into a request in an outbound integration (or hopefully a custom step in flow designer?) and make the request. Back when we first wrote this, there wasn't even an API to talk to, so we didn't create any of the outbound integration pieces to do so. Actually, this outbound step wouldn't be a bad idea for our new Step Library. |
it,s not a problem with alertmanager silence, i am talking about script
for mapping fields from inbound messages to outbound. Prepared like for
Icinga integration.
…On Wed, Aug 21, 2019, 19:33 Travis DePuy ***@***.***> wrote:
Hey @Alexvianet <https://github.com/Alexvianet>. Does Prometheus provide
a silence API? They don't list one specifically here
<https://prometheus.io/docs/prometheus/latest/querying/api/#alerts>. But
I did see this thread
<prometheus/alertmanager#511 (comment)>
that mentions you might be able to do something like
curl -H "Content-Type: application/json" -X POST -d '{
"comment": "test1",
"createdBy": "test1",
"endsAt": "2019-02-20T18:00:59.46418637Z",
"matchers": [
{
"isRegex": false,
"name": "severity",
"value": "critical"
},
{
"isRegex": false,
"name": "job",
"value": "prometheus"
},
{
"isRegex": false,
"name": "instance",
"value": "localhost:9090"
},
{
"isRegex": false,
"name": "alertname",
"value": "InstanceDown"
}]
}' http://alerts.example.org:9093/api/v1/silences
So you could turn that into a request in an outbound integration (or
hopefully a custom step in flow designer?) and make the request. Back when
we first wrote this, there wasn't even an API to talk to, so we didn't
create any of the outbound integration pieces to do so.
Actually, this outbound step wouldn't be a bad idea for our new Step
Library <https://github.com/xmatters/xMatters-Labs-Flow-Steps>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3?email_source=notifications&email_token=AEFMOROXASMER6IGPDH6WD3QFVU7HA5CNFSM4IOJEUMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD42JPDQ#issuecomment-523540366>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEFMORLD4K4H2X3VOML2JTDQFVU7HANCNFSM4IOJEUMA>
.
|
Ah, I see. I think we'll probably take this one in the direction of Flow Designer, but we still need import/export support for the canvas, which should be coming in the next month or two. Until then, it shouldn't be too hard to add this yourself. On the Flows tab, you can create a new flow and drag in the appropriate outbound trigger you want to work with. Some details here. The steps have support for running in an xMatters Agent, useful if the systems you want to call are behind a firewall. Is that what you are looking for? |
looks like, thanks
…On Thu, Aug 22, 2019, 01:06 Travis DePuy ***@***.***> wrote:
Ah, I see. I think we'll probably take this one in the direction of Flow
Designer
<https://help.xmatters.com/ondemand/xmodwelcome/flowdesigner/flow-designer.htm?cshid=FlowDesignerPlace>,
but we still need import/export support for the canvas, which should be
coming in the next month or two.
Until then, it shouldn't be too hard to add this yourself. On the Flows
tab, you can create a new flow and drag in the appropriate outbound trigger
you want to work with. Some details here
<https://help.xmatters.com/ondemand/xmodwelcome/flowdesigner/flow-triggers.htm#EventActivityTriggers>.
The steps have support for running in an xMatters Agent, useful if the
systems you want to call are behind a firewall.
Is that what you are looking for?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3?email_source=notifications&email_token=AEFMORO7U4QUXR6QFLJSAO3QFW357A5CNFSM4IOJEUMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD43IT4I#issuecomment-523667953>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEFMORLTD5O57OKQ5CLDFWDQFW357ANCNFSM4IOJEUMA>
.
|
Cool. Happy to help. I'll keep this open so we can track the request when we revisit the integration. |
@xMTinkerer any updates with import-export support? for Outbound Integration ? |
Hey @Alexvianet! Yep, we now have import-export! I've added this item to the stack, but I'm not sure I can provide a timeframe at this point. |
Ok, cool. There are two options. The first is to use the "Response" trigger that would fire when a user responded. Unfortunately, this doesn't take dynamic input (such as the comment screen in your screenshot). This means you need to set up the static responses such as "Silence 1h", "Silence 2h". etc. Then the script will need to parse out the "2h" and run the script. Unfortunately there might be a problem. In order to enter comments, you have to respond first. In order to get your response into the system ASAP, we process the response immediately. But since we have to wait for user input for the comment, we wait to trigger the comment until they click submit on the comment. This means a comment will trigger the Response trigger as well as the Comment trigger. Anyway, assuming you want to go with the comments route, you will add a new outbound script that looks like so: The agent has access to a Shell (doc here). I took a stab based on the command you provided (caution, untested): //Create a shell by requiring the xm-shell library.
//If the integration is running in the cloud then this call will fail.
if( annotation.response.response.toLowerCase() != 'silence' ) {
console.log( 'Ignoring response "' + annotation.response.response + '"' );
return;
}
try
{
var Shell = require('xm-shell');
}
catch (e)
{
console.log("Could not load library:" + e);
console.log("Running in cloud - exiting.");
}
// Probably need some error checking if the user
// didn't enter a positive integer..
// or a bash injection...
var duration = annotation.comment;
// request the operating system name from the shell
var osname = Shell.osname();
// create a script and pass some parameters into it.
var script = Shell.script(function () {/*#### PLACE YOUR BASH SCRIPT BETWEEN HERE ####
echo hello world
/usr/local/bin/amtool --alertmanager.url http://localhost:9093 silence add \
alertname="${alertname}" --comment="${comment}" --author="${author}" --duration="${duration}h"
#### AND HERE #### */},
{ alertname: 'ALERTNAME FROM Inbound',
comment: 'User ' + annotation.author.targetName + ' slienced alert.',
author: annotation.author.targetName,
duration: annotation.comment
});
// Execute the script.
console.log(Shell.exec('bash', script).output());
console.log(Shell.exec('bash', script).exitCode());
console.log(Shell.exec('bash', script).error()); You can see the You can see details on the Comments trigger here and the Let me know how you get on with that! |
thanks a lot, need to figure out how to set duration when push acknowledge
button)
…On Fri, Oct 25, 2019, 18:55 Travis DePuy ***@***.***> wrote:
Ok, cool. There are two options. The first is to use the "Response"
trigger that would fire when a user responded. Unfortunately, this doesn't
take dynamic input (such as the comment screen in your screenshot). This
means you need to set up the static responses such as "Silence 1h",
"Silence 2h". etc. Then the script will need to parse out the "2h" and run
the script.
The other option is to use the "Comments" trigger and allow the user to
enter a number. There isn't a way to add a second input field, so we'll
have to use the comments input box.
Unfortunately there might be a problem. In order to enter comments, you
have to respond first. In order to get your response into the system ASAP,
we process the response immediately. But since we have to wait for user
input for the comment, we wait to trigger the comment until they click
submit on the comment. This means a comment will trigger the Response
trigger as well as the Comment trigger.
I'm not sure the behavior of the amtool if someone adds multiple silences,
so this is something to keep in mind. I'd be interested in your take on
this.
Anyway, assuming you want to go with the comments route, you will add a
new outbound script that looks like so:
[image: image]
<https://user-images.githubusercontent.com/10202041/67585394-4ae59300-f704-11e9-9b00-88ce3159ad8c.png>
The agent has access to a Shell (doc here
<https://help.xmatters.com/ondemand/xmodwelcome/xmattersagent/writing-xmatters-agent-scripts.htm>).
I took a stab based on the command you provided (*caution*, untested):
//Create a shell by requiring the xm-shell library.//If the integration is running in the cloud then this call will fail.
if( annotation.response.response.toLowerCase() != 'silence' ) {
console.log( 'Ignoring response "' + annotation.response.response + '"' );
return;
}
try
{
var Shell = require('xm-shell');
}catch (e)
{
console.log("Could not load library:" + e);
console.log("Running in cloud - exiting.");
}
// Probably need some error checking if the user// didn't enter a positive integer..// or a bash injection...var duration = annotation.comment;
// request the operating system name from the shellvar osname = Shell.osname();// create a script and pass some parameters into it.var script = Shell.script(function () {/*#### PLACE YOUR BASH SCRIPT BETWEEN HERE ####echo hello world/usr/local/bin/amtool --alertmanager.url http://localhost:9093 silence add \ alertname="${alertname}" --comment="${comment}" --author="${author}" --duration="${duration}h" #### AND HERE #### */},
{ alertname: 'ALERTNAME FROM Inbound',
comment: 'User ' + annotation.author.targetName + ' slienced alert.',
author: annotation.author.targetName,
duration: annotation.comment
});
// Execute the script.console.log(Shell.exec('bash', script).output());console.log(Shell.exec('bash', script).exitCode()); console.log(Shell.exec('bash', script).error());
You can see the alertname, comment, author, and duration parameters being
passed into the Shell script and referenced appropriately.
You can see details on the Comments trigger here
<https://help.xmatters.com/ondemand/xmodwelcome/integrationbuilder/create-outbound-updates.htm#Event>
and the annotation object here
<https://help.xmatters.com/ondemand/xmodwelcome/integrationbuilder/scripting-reference.htm#Comments>
Let me know how you get on with that!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3?email_source=notifications&email_token=AEFMORPZS5XEIFMZ5CDRYK3QQMJIRA5CNFSM4IOJEUMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECIY76I#issuecomment-546410489>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEFMORN7MPBFWOFGTKGQCE3QQMJIRANCNFSM4IOJEUMA>
.
|
If you just want to send the silence command to Alertmanager for a set duration every time, then you could use the Response trigger and set |
Oh and I think for the Comments trigger, to help deal with shell injection issues and validate the input is in the correct format, you could use this little expression on the var duration = annotation.comment;
// Validate the comment is in the form Nh, where
// N is 1 or 2 digits and the h is optional
if( !duration.match( /\d{1,2}h?/ ) ) {
console.log( 'Comment "' + duration + '" is not in expected format of "Nh"' );
return;
} Edit, added a note explaining the RegEx |
My script:
and get: |
Hrm, that's not good. Can you post the details of the |
xmatter systemd:
/var/log/xmatters/xmatters-xa/agent-communication-xmatters.log got:
|
@Alexvianet Did you ever get this resolved? Are you still having issues with the agent? |
nope i am stuck on previous comment, and was busy with other stuff |
Darn. Can you open a support ticket when you get a chance? I don't have insight to the backend to debug further. Cruise over here and they'll help you out: |
I can't find any documentation for Outbound Integration to acknowledge alerts and move them to silence for some period
The text was updated successfully, but these errors were encountered: