Rocketchat integration with AWX Tower notification - rocket.chat

I'm looking for a way how to integrate a notification for Ansible Tower / AWX to Rocket.Chat? I can't find a suitable script for Rocket.Chat integration.

First go in Rocket.Chat in Administration > Integration and then create a new incoming webhook. Configure it as wanted (name, bot, channel, etc.) enable scripting and add the following script:
class Script {
process_incoming_request({ request }) {
// UNCOMMENT THE BELOW LINE TO DEBUG IF NEEDED.
// console.log(request.content);
let body = request.content.body;
if (!body) {
let id = request.content.id;
let name = request.content.name;
let url = request.content.url;
let status = request.content.status;
let type = request.content.friendly_name;
let project = request.content.project;
let playbook = request.content.playbook;
let hosts = request.content.hosts;
let created_by = request.content.created_by;
let started = request.content.started;
let finished = request.content.finished;
let traceback = request.content.traceback;
let inventory = request.content.inventory;
let credential = request.content.credential;
let limit = request.content.limit;
let extra_vars = request.content.extra_vars;
let message = "";
message += "AWX "+type+" "+name+" ("+id+") ";
message += "on project _"+project+"_ ";
message += "running playbook _"+playbook+"_ ";
message += "has status *"+status+"*.";
message += "\n";
message += type+" was created by _"+created_by+"_ for inventory _"+inventory+"_ ";
if (limit !== "") {
message += "with limit _"+limit+"_ ";
}
message += " and using the _"+credential+"_ credentials.\n";
if (Object.keys(hosts).length != 0) {
message += "Hosts: "+Object.keys(hosts).length+" (ok/changed/skipped/failures)\n";
for (let [name, host] of Object.entries(hosts)) {
message += "- "+name+" ("+host.ok+"/"+host.changed+"/"+host.skipped+"/"+host.failures+")";
if (host.failed === false) {
message += " is *ok*\n";
} else {
message += " has *failed*\n";
}
}
}
return {
content: {
"text": "AWX notification *"+status+"* on "+type+" "+name+" ("+id+")",
"attachments": [
{
"title": type+": "+name+"",
"title_link": url,
"text": message,
"color": "#764FA5"
}
]
}
};
} else {
return {
content: {
text: "AWX notification: " + request.content.body
}
};
}
}
}
Save and activate the webhook. Now you get a Webhook URL from Rocket.Chat. Copy that URL.
Go to your AWX instance and create a new Notification of type Webhook and paste the Webhook URL from Rocket.Chat. You can test the notifcation within AWX.
The script does not print extra vars, because they could contain passwords etc. But you'll see failed hosts and some more information about the job.

AWX/Tower has the ability to send notifications to rocket.chat without any custom scripts.
In Tower go to Notifications and add a new one with type 'Rocket.Chat' then set the Target URL to be the URL of a blank incoming webhook in Rocket.Chat (Make sure it's enabled at the top).
(Note: Be careful of the URL Rocket.Chat gives you for the integration, mine didn't give me a URL with the correct port of 3000 within the URL so it failed at first)
Heres what the notifcations read as:
Bot -
3:13 PM
Tower Notification Test 1 https://ruupansi01
Bot -
3:15 PM
Project Update #2 'Test Project' succeeded: https://tower/#/jobs/project/1

Related

Triggering a Lambda once a DMS Replication Task has completed in Terraform

I would like to trigger a Lambda once an RDS Replication Task has successfully completed. I have the following Terraform code, which successfully creates all the assets, but my Lambda is not being triggered.
resource "aws_dms_event_subscription" "my_event_subscription" {
enabled = true
event_categories = ["state change"]
name = "my-event-subscription"
sns_topic_arn = aws_sns_topic.my_event_subscription_topic.arn
source_ids = ["my-replication-task"]
source_type = "replication-task"
}
resource "aws_sns_topic" "my_event_subscription_topic" {
name = "my-event-subscription-topic"
}
resource "aws_sns_topic_subscription" "my_event_subscription_topic_subscription" {
topic_arn = aws_sns_topic.my_event_subscription_topic.arn
protocol = "lambda"
endpoint = aws_lambda_function.my_lambda_function.arn
}
resource "aws_sns_topic_policy" "allow_publish" {
arn = aws_sns_topic.my_event_subscription_topic.arn
policy = data.aws_iam_policy_document.allow_dms_and_events_document.json
}
resource "aws_lambda_permission" "allow_sns_invoke" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.my_lambda_function.function_name
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.my_event_subscription_topic.arn
}
data "aws_iam_policy_document" "allow_dms_and_events_document" {
statement {
actions = ["SNS:Publish"]
principals {
identifiers = [
"dms.amazonaws.com",
"events.amazonaws.com"
]
type = "Service"
}
resources = [aws_sns_topic.my_event_subscription_topic.arn]
}
}
Am I missing something?
Is event_categories = ["state change"] correct? (This suggests state change is correct.
I'm less concerned right now if the Lambda is triggered for every state change, and not just DMS-EVENT-0079.)
Is there something I can add to get CloudWatch logs from the event subscription, to tell me what's wrong?
You can try giving it a JSON as shared on AWS Documentation.
{
"version":"0",
"id":"11a11b11-222b-333a-44d4-01234a5b67890",
"detail-type":"DMS Replication Task State Change",
"source":"aws.dms",
"account":"0123456789012",
"time":"1970-01-01T00:00:00Z",
"region":"us-east-1",
"resources":[
"arn:aws:dms:us-east-1:012345678901:task:AAAABBBB0CCCCDDDDEEEEE1FFFF2GGG3FFFFFF3"
],
"detail":{
"type":"ReplicationTask",
"category":"StateChange",
"eventType":"REPLICATION_TASK_STARTED",
"eventName":"DMS-EVENT-0069",
"resourceLink":"https://console.aws.amazon.com/dms/v2/home?region=us-east-1#taskDetails/taskName",
"detailMessage":"Replication task started, with flag = fresh start"
}
}
You can check how to give this as JSON in Terraform here

i want to change workflow status based on jenkins build with project name and status

I want to change workflow status based on jenkins build with project name and status. can anyone please help me out on this. I am able to do as below: with story-id
def transitionInput = [transition: [id: '41']]
jiraTransitionIssue idOrKey: 'MSDP-198', input: transitionInput, site: 'JIRA'
but I need to list story id based on project name and status
success {
script {
def searchResults = jiraJqlSearch jql: "PROJECT = 'MSDP' and status = 'READY FOR STAGING DEPLOYMENT' and type = 'Story'", site: 'JIRA'
def issues = searchResults.data.issues
for (i = 0; i <issues.size(); i++) {
def result = jiraGetIssue idOrKey: issues[i].key, site: 'JIRA'
def transitionInput = [transition: [id: '41']]
def statuses = jiraGetProjectStatuses idOrKey: 'MSDP', site: 'JIRA'
responce = jiraTransitionIssue idOrKey: issues[i].key, input: transitionInput, site: 'JIRA'
}
}
} }

Terraform: CloudWatch Event that notifies SNS

I'm learning TF and trying to apply an infrastructure that creates:
a simple lambda function
an SNS topic
get that lambda to subscribe the SNS topic
a Cloud Watch Event that publishes a message to the topic at some interval
a Cloud Watch Log Group to check if the lambda gets notified by the SNS
The lambda permission to allow calls from SNS
I'm able to apply that successfully. The infrastructure seems perfectly fine (it has the same aspect when I create that myself through the visual aws console)
But the cloud watch Event doesn't get triggered (when built from TF), so no message is published to SNS and lambda doesn't get called. I don't know why
Anyone know how can I accomplish that? Bellow my .tf script:
provider "aws" {
region = "us-east-1"
}
//lambda function handler & code file
resource "aws_lambda_function" "lambda-function" {
function_name = "Function01"
handler = "com.rafael.lambda.Function01"
role = "arn:aws:iam::12345:role/LambdaRoleTest"
runtime = "java8"
s3_bucket = aws_s3_bucket.sns-test.id
s3_key = aws_s3_bucket_object.file_upload.id
source_code_hash = filebase64sha256("../target/sns-cw-lambda-poc.jar")
}
//allow sns to call lambda
resource "aws_lambda_permission" "allow-sns-to-lambda" {
function_name = aws_lambda_function.lambda-function.function_name
action = "lambda:InvokeFunction"
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.call-lambdas-topic.arn
statement_id = "AllowExecutionFromSNS"
}
//app s3 repository
resource "aws_s3_bucket" "sns-test" {
bucket = "app-bucket-12345"
region = "us-east-1"
}
//app jar file
resource "aws_s3_bucket_object" "file_upload" {
depends_on = [
aws_s3_bucket.sns-test
]
bucket = aws_s3_bucket.sns-test.id
key = "sns-cw-lambda-poc.jar"
source = "../target/sns-cw-lambda-poc.jar"
server_side_encryption = "AES256"
etag = filebase64sha256("../target/sns-cw-lambda-poc.jar")
}
//to check lambda exec logs
resource "aws_cloudwatch_log_group" "lambda-cloudwatch-logs" {
name = "/aws/lambda/${aws_lambda_function.lambda-function.function_name}"
retention_in_days = 1
}
//rule to trigger SNS
resource "aws_cloudwatch_event_rule" "publish-sns-rule" {
name = "publish-sns-rule"
schedule_expression = "rate(1 minute)"
}
//cloud watch event targets SNS
resource "aws_cloudwatch_event_target" "sns-publish" {
count = "1"
rule = aws_cloudwatch_event_rule.publish-sns-rule.name
target_id = aws_sns_topic.call-lambdas-topic.name
arn = aws_sns_topic.call-lambdas-topic.arn
}
//SNS topic to subscribe
resource "aws_sns_topic" "call-lambdas-topic" {
name = "call-lambdas-topic"
}
//lambda subscribes the topic, so it should be nofied when other resource publishes to the topic
resource "aws_sns_topic_subscription" "sns-lambda-subscritption" {
topic_arn = aws_sns_topic.call-lambdas-topic.arn
protocol = "lambda"
endpoint = aws_lambda_function.lambda-function.arn
}
I figured it out, I forgot to add the SNS policies that allow CloudWatch to publish to SNS topic. To get the above script to work, just add this:
resource "aws_sns_topic_policy" "default" {
count = 1
arn = aws_sns_topic.call-lambdas-topic.arn
policy = "${data.aws_iam_policy_document.sns_topic_policy.0.json}"
}
data "aws_iam_policy_document" "sns_topic_policy" {
count = "1"
statement {
sid = "Allow CloudwatchEvents"
actions = ["sns:Publish"]
resources = [aws_sns_topic.call-lambdas-topic.arn]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
}
}

Icinga2 notification just once on state change

I have set up icinga2 to monitor a few services with different intervals, so one service might be checked every 10 seconds. If it gives a critical error I will receive a notification, but I will receive it every 10 seconds if the error persists, or until I acknowledge it. I just want to receive it once for each state change. Then maybe after a specified time again, but it is not that important.
Here is my config:
This is more or less the standard template.conf, but I have added the "interval=0s", because I read that it should prevent notifications from being sent multiple times.
template Notification "mail-service-notification" {
command = "mail-service-notification"
interval = 0s
states = [ OK, Critical ]
types = [ Problem, Acknowledgement, Recovery, Custom,
FlappingStart, FlappingEnd,
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
vars += {
notification_logtosyslog = false
}
period = "24x7"
}
And here is the part of the notification.conf that includes the template:
object NotificationCommand "telegram-service-notification" {
import "plugin-notification-command"
command = [ SysconfDir + "/icinga2/scripts/telegram-service-notification.sh" ]
env = {
NOTIFICATIONTYPE = "$notification.type$"
SERVICEDESC = "$service.name$"
HOSTNAME = "$host.name$"
HOSTALIAS = "$host.display_name$"
HOSTADDRESS = "$address$"
SERVICESTATE = "$service.state$"
LONGDATETIME = "$icinga.long_date_time$"
SERVICEOUTPUT = "$service.output$"
NOTIFICATIONAUTHORNAME = "$notification.author$"
NOTIFICATIONCOMMENT = "$notification.comment$"
HOSTDISPLAYNAME = "$host.display_name$"
SERVICEDISPLAYNAME = "$service.display_name$"
TELEGRAM_BOT_TOKEN = TelegramBotToken
TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$"
}
}
apply Notification "telegram-icingaadmin" to Service {
import "mail-service-notification"
command = "telegram-service-notification"
user_groups = [ "icingaadmins" ]
assign where host.name
}
I think you had a typo.
It should work if you set interval = 0 (not "interval = 0s")
After that change you must restart the icinga service.

How to Change app_id for Paypal xcode api

I have a log when user finnish payment.
I need to change app_id but i can't to find it.
This is my log
Here is your proof of payment:
{
client = {
environment = mock;
"paypal_sdk_version" = "1.0.5";
platform = iOS;
"product_name" = "PayPal iOS SDK";
};
payment = {
amount = "1.00";
"currency_code" = USD;
"short_description" = "Hipster t-shirt";
};
"proof_of_payment" = {
"adaptive_payment" = {
"app_id" = "APP-1234567890";
"pay_key" = "AP-70M68096ML426802W";
"payment_exec_status" = COMPLETED;
timestamp = "2013-07-05T02:20:57Z";
};
};
}
Send this to your server for confirmation and fulfillment.
#Lmstart, "APP-1234567890" is the app-id provided when you are running the PayPal iOS SDK in its "mock" environment, PayPalEnvironmentNoNetwork. If you switch to PayPalEnvironmentSandbox or PayPalEnvironmentProduction you should instead see an application ID corresponding to your app.

Resources