How to create a custom Ambari alert dispatcher - notifications

I am trying to create an alert notification on ambari choosing alert script as method. Here are the steps I have followed:
Create an alert target using Create Alert Notification screen
{
"AlertTarget":
{
"name": "test_dispatcher",
"description": "Custom Notification Dispatcher",
"notification_type": "ALERT_SCRIPT",
"global": true,
"alert_states": ["CRITICAL","WARNING","UNKNOWN","OK"],
"properties": {
"ambari.dispatch-property.script": "notification.dispatch.alert.script",
"ambari.dispatch-property.script.filename" : "customdispatcher.py"
}
}
}
Create customdispatcher.py in /var/lib/ambari-server/resources/scripts/
## Writing notification to a file. Use your own logic here.
file = open("/var/log/ambari-server/custom_notification.log", "a+")
file.write("New notifiation")
file.close()
if __name__ == '__main__':
handle_alert()
Change file permissions.
chmod 777 /var/lib/ambari-server/resources/scripts/customdispatcher.py
chmod +x /var/lib/ambari-server/resources/scripts/customdispatcher.py
Add following line to ambari properties file
notification.dispatch.alert.script=/var/lib/ambari-server/resources/scripts/customdispatcher.py
Restart ambari
After these steps, I stop some services to trigger an alarm but get a warning in /var/log/ambari-server/ambari-server.log file and nothing is logged to custom_notification.log file.
2022-06-23 09:38:53,144 WARN [script-dispatcher-1] AlertScriptDispatcher$AlertScriptRunnable:363 - Unable to dispatch ALERT_SCRIPT notification because /var/lib/ambari-server/resources/scripts/customdispatcher.py terminated with exit code 2
Any ideas on how to fix this?

Related

Chalice on_s3_event trigger seems to not work

I have a Chalice app that reads config data from a file in an S3 bucket. The file can change from time to time, and I want the app to immediately use the updated values, so I am using the on_s3_event decorator to reload the config file.
My code looks something like this (stripped way down for clarity):
CONFIG = {}
app = Chalice(app_name='foo')
#app.on_s3_event(bucket=S3_BUCKET, events=['s3:ObjectCreated:*'],
prefix='foo/')
def event_handler(event):
_load_config()
def _load_config():
# fetch json file from S3 bucket
CONFIG['foo'] = some item from the json file...
CONFIG['bar'] = some other item from the json file...
_load_config()
#app.route('/')
def home():
# refer to CONFIG values here
My problem is that for a short while (maybe 5-10 minutes) after uploading a new version of the config file, the app still uses the old config values.
Am I doing this wrong? Should I not be depending on global state in a Lambda function at all?
So your design here is flawed.
When you create an S3 Event in chalice it will create a separate Lambda function for that event. the CONFIG variable would get updated in the running instance of that Lambda function and all new instances of the Lambda function. However any other Lambdas in your Chalice app that are already running would just continue on with their current settings until they were cleaned up and restarted.
If you cannot live with a config that is only changeable when you deploy your Lambda functions you could use redis or some other in memory cache/db.
You should be using the .config/config.json file to store your variables for your chalice application. Those variables are stored in the os library and can be called:
URL = os.environ['MYVAR']
Your config.json file might look like this:
{
"version": "2.0",
"app_name": "MyApp",
"manage_iam_role": false,
"iam_role_arn": "arn:aws:iam::************:role/Chalice",
"lambda_timeout": 300,
"stages": {
"development": {
"environment_variables": {
"MYVAR": "foo"
}
},
"production": {
"environment_variables": {
"MYVAR": "bar"
}
}
},
"lambda_memory_size": 2048
}

IntelliJ Find Action on Mac opens terminal app by error

When I press Cmd + Shift + A in IntelliJ it should open the "Find Action..." dialog. Instead it opens Terminal.app with the apropos command.
How can I resolve this problem?
Seems in MacOs 10.14.4 a new default shortcut was enabled - Services -> Search man Page Index in Terminal. It uses the same shortcut as Find Action - Cmd+Shift+A. As a result using Find Action in the IDE could sometimes open terminal window with apropos <smth> command output.
Explicit Location: System Preferences > Keyboard > Shortcuts > Services (on left hand side) > (uncheck) Search man Page Index in Terminal
Here’s a script (hosted in gist) that will do this via the command line, which might be useful for an organisation that wants to roll out this change for a number of users.
TEMP_SETTINGS_FILE=$(mktemp -t 'man-shortcuts-off.json')
cat > $TEMP_SETTINGS_FILE <<EOF
{
"NSServicesStatus": {
"com.apple.Terminal - Open man Page in Terminal - openManPage": {
"presentation_modes": {
"ContextMenu": false,
"ServicesMenu": false
},
"enabled_context_menu": false,
"enabled_services_menu": false
},
"com.apple.Terminal - Search man Page Index in Terminal - searchManPages": {
"presentation_modes": {
"ContextMenu": false,
"ServicesMenu": false
},
"enabled_context_menu": false,
"enabled_services_menu": false
}
}
}
EOF
# Settings are stored in the pbs domain. Other settings in this domain will not be overwritten. I’ve included the settings to change in JSON for brevity. They are converted to XML (which `defaults import` expects) before being imported.
plutil -convert xml1 -o - ${TEMP_SETTINGS_FILE} | defaults import pbs -
rm ${TEMP_SETTINGS_FILE}

basic puppet construct not working, why?

I have created a puppet construct: the file-scructure can be taken out of the screenshot below.
But when I execute the sites.pp file with the following command...
sudo puppet apply manifests/sites.pp --modulepath=~/puppet/modules/
...I get an errormessage as it is shown in the screenshot below.
manifests/sites.pp:
import 'nodes.pp'
manifests/nodes.pp:
node 'rbalwprinst01' {
include teamviewer
}
modules/teamviewer/manifests/init.pp:
class teamviewer {
file { '/tmp/test':
content => "test",
}
}
What is the cause of this error?
Thanks in advance.
EDIT: The solution to the problem was to remove "sudo", so that the command gets executed by the normal user.

Why Icinga2 telegram notification fails in specific services?

I have created custom telegram notification very similar to email notifications. The problem is that it works for hosts and most of the services but not for all of them.
I do not post the *.sh files in scripts folder as it works!
In constants.conf I have added the bot token:
const TelegramBotToken = "MyTelegramToken"
I wanted to manage telegram channels or chat ids in users file, so I have users/user-my-username.conf as below:
object User "my-username" {
import "generic-user"
display_name = "My Username"
groups = ["faxadmins"]
email = "my-username#domain.com"
vars.telegram_chat_id = "#my_channel"
}
In templates/templates.conf I have added the below code:
template Host "generic-host-domain" {
import "generic-host"
vars.notification.mail.groups = ["domainadmins"]
vars.notification["telegram"] = {
users = [ "my-username" ]
}
}
template Service "generic-service-fax" {
import "generic-service"
vars.notification["telegram"] = {
users = [ "my-username" ]
}
}
And in notifications I have:
template Notification "telegram-host-notification" {
command = "telegram-host-notification"
period = "24x7"
}
template Notification "telegram-service-notification" {
command = "telegram-service-notification"
period = "24x7"
}
apply Notification "telegram-notification" to Host {
import "telegram-host-notification"
user_groups = host.vars.notification.telegram.groups
users = host.vars.notification.telegram.users
assign where host.vars.notification.telegram
}
apply Notification "telegram-notification" to Service {
import "telegram-service-notification"
user_groups = host.vars.notification.telegram.groups
users = host.vars.notification.telegram.users
assign where host.vars.notification.telegram
}
This is all I have. As I have said before it works for some services and does not work for other services. I do not have any configuration in service or host files for telegram notification.
To test I use Icinga web2. Going to a specific service in a host and send custom notification. When I send a custom notification I check the log file to see if there is any error and it says completed:
[2017-01-01 11:48:38 +0000] information/Notification: Sending reminder 'Problem' notification 'host-***!serviceName!telegram-notification for user 'my-username'
[2017-01-01 11:48:38 +0000] information/Notification: Completed sending 'Problem' notification 'host-***!serviceName!telegram-notification' for checkable 'host-***!serviceName' and user 'my-username'.
I should note that email is sent as expected. There is just a problem in telegram notifications for 2 services out of 12.
Any idea what would be the culprit? What is the problem here? Does return of scripts (commands) affect this behaviour?
There is no Telegram config in any service whatsoever.
Some telegram commands may fail due to markdown parser.
I've encountered this problem:
If service name has one underscore ('_'), then parser will complain about not closed markdown tag and message will not be sent

Icinga2 notifications does not execute notification command

I'm trying to configure icinga2 notification. I restart icinga2 and no error occurs. But my notification command does not execute. I defined user, template and applied notification to host, notification command for notification (as below) and turned on notification feature, i don't know why my script did not run. Anyone in forum used to configure icinga2 notification can give me full steps to configure icinga notification.
Notification Command
object NotificationCommand "test-notification" {
import "plugin-notification-command"
command = [ "/etc/icinga2/scripts/test.sh" ]}
Notification template
template Notification "generic-notification" {
command = "test-notification"
period = "test-24x7"
user_groups = [ "icinga" ]}
User
object User "icinga" {
import "generic-user"
display_name = "Icinga 2 Admin"
enable_notifications = true
email = "icinga#localhost"}
Notification
apply Notification "test-notification" to Host {
import "generic-notification"
users = [ "icinga" ]
assign where host.display_name}
You should try to verify that the execution is not working if not happen yet. Is it executable (chmod +x test.sh)?:
In your test.sh you could do something like
echo "script executed" >> /tmp/doesmyscriptrun.txt
Have a look to your file:
cat /tmp/doesmyscriptrun.txt