#255: Implement Slack Alert Notifications for Nagios Monitoring - Rmhibbert/oe2-group-c GitHub Wiki
Step by step
Direct to the puppet module path
Description:
Command: cd /etc/puppetlabs/code/modules
Create a folder
Description:
Command: sudo mkdir -p slack_plugin/{manifests,files,templates}
direct to slack_plugin file
Description:
Command: cd slack_plugin/files
Install the Perl modules
Description:
Command:
class your_module_name {
# Install required Perl modules
package { [
'libwww-perl',
'libcrypt-ssleay-perl',
'liblwp-protocol-https-perl',
]:
ensure => installed,
}
}
get the web
Description:
Command: sudo wget https://raw.github.com/tinyspeck/services-examples/master/nagios.pl
edit the nagios.pl file $opt domain and $opt token
Description:
Command: domain: operationseng-rck5174.slack.com token: j1nIe77sGiGKvdsQOP12IwMn
Copy file to /usr/lib/nagios/plugins/ and give it 0755
Description:
Command: sudo cp nagios.pl /usr/lib/nagios/plugins/
, sudo chmod 0755 /usr/lib/nagios/plugins/nagios.pl
Edit the install.pp file
Description:
Command:
class nagios_slack_alert::install { package { ['libwww-perl', 'libcrypt-ssleay-perl', 'liblwp-protocol-https-perl']: ensure => installed, } file { '/usr/lib/nagios/plugins/nagios.pl': ensure => file, mode => '0755', source => 'puppet:///modules/slack_plugin/nagios.pl', require => Package['libwww-perl'], } file { '/etc/nagios-plugins/config/slack.cfg': ensure => file, content => template('slack_plugin/slack.cfg.erb'), require => File['/usr/lib/nagios/plugins/nagios.pl'], } }
edit config.pp
Description:
Command:
class nagios_slack_alert::config { nagios_contact { 'slack': target => '/etc/nagios4/conf.d/ppt_contacts.cfg', alias => 'Slack', service_notification_period => '24x7', host_notification_period => '24x7', service_notification_options => 'w,u,c,r', host_notification_options => 'd,u,r', service_notification_commands => 'notify-service-by-slack', host_notification_commands => 'notify-host-by-slack', email => 'root@localhost', } nagios_contactgroup { 'slackgroup': target => '/etc/nagios4/conf.d/ppt_contactgroups.cfg', alias => 'Slack Channel', members => 'slack', } }
Edit init.pp
Description:
Command:
class nagios_slack_alert { include nagios_slack_alert::install insclude nagios_slack_alert::config }
add this command into slack.cfg.erb
Description:
Command:
define command { command_name notify-service-by-slack command_line /usr/lib/nagios/plugins/nagios.pl -field slack_channel=#group-c -field \ HOSTALIAS="$HOSTNAME$" -field SERVICEDESC="$SERVICEDESC$" \ 1 -field SERVICESTATE="$SERVICESTATE$" -field SERVICEOUTPUT="$SERVICEOUTPUT$" \ -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" }
define command { command_name notify-host-by-slack command_line /usr/lib/nagios/plugins/nagios.pl -field slack_channel=#group-c -field \ HOSTALIAS="$HOSTNAME$" -field HOSTSTATE="$HOSTSTATE$" \ -field HOSTOUTPUT="$HOSTOUTPUT$" \ -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" }
create a file call ppt_contacts.cfg in /ect/nagios4/conf.d
Description:
Command:
nagios_contact { 'slack': target => '/etc/nagios4/conf.d/ppt_contacts.cfg', alias => 'Slack', service_notification_period => '24x7', host_notification_period => '24x7', service_notification_options => 'w,u,c,r', host_notification_options => 'd,r', service_notification_commands => 'notify-service-by-slack', host_notification_commands => 'notify-host-by-slack', email => 'root@localhost', }
create a ppt_contactgroups.cfg file, and add this code
Description:
Command:
nagios_contactgroup { 'slackgroup': target => '/etc/nagios4/conf.d/ppt_contactgroups.cfg', # The file where the contact group will be defined alias => 'Slack Channel', # The name of the contact group members => 'slack', # Add the Slack contact to this group }
Include nagios_slack_alert in site.pp
Description:
Command: include nagios_slack_alert
Description:
Command:
Description:
Command:
Challenges
Text