How to Install and Setup Sensu in Centos-7

SHORT INTRODUCTION

Sensu is an agent-based monitoring tool that you use into your organization’s infrastructure. Sensu’s agent gives you visibility into everything you care about. The Sensu backend provides you with flexible, functional automatic defaults to route metrics and alerts. Sensu is designed to monitor everything from server transparency to the cloud. Sensu’s open architecture makes it easy to integrate monitoring with tools you already use such as Nagios, Chef, Graphite, InfluxDB, and PagerDuty plugins. Sensu gives you full control of your displays with variable filters, full context notifications, reporting, event management and auto-correction.

Here, we are using two servers :

 sensu – 192.168.33.47

 client_sensu – 192.168.33.40

Login to client_sensu – 192.168.33.40

Step 1: install the Epel-release

[root@client_sensu ~]# yum install epel-release -y

Install wget & vim too if you didn’t have :

[root@client_sensu ~]# yum install wget vim -y

Step 2: Install Erlang

[root@client_sensu ~]# yum install erlang -y

Step 3 : Install Sensu

Add repository first –

[root@client_sensu ~]# echo '[sensu]
name=sensu
baseurl=https://eol-repositories.sensuapp.org/yum/$releasever/$basearch/
gpgcheck=0
enabled=1' | sudo tee /etc/yum.repos.d/sensu.repo

Now, Install Sensu, Redis & Import Rabbitmq –

[root@client_sensu ~]# yum install sensu -y
[root@client_sensu ~]# yum install redis -y
[root@client_sensu ~]# rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc

Step 4 : Now, Inserting some Repositories :

*client.json –

[root@client_sensu ~]# cd /etc/sensu/conf.d
[root@client_sensu ~]# vim client.json

Copy Paste the below lines in the file & change your server-ip-

{
  "client": {
    "name": "mysecondclient",
    "address": "192.168.33.47",
    "subscriptions": [
      "default",
      "webserver",
      "production"
    ]
  }
}

*transport.json –

[root@client_sensu ~]# vim transport.json

Copy Paste the below lines in the file –

{
  "transport": {
    "name": "rabbitmq",
    "reconnect_on_error": true
  }
}
 

*rabbitmq.json –

[root@client_sensu ~]# vim rabbitmq.json

Copy Paste the below lines in the file & change your server-ip –

{
  "rabbitmq": {
    "host": "192.168.33.47",
    "port": 5671,
    "vhost": "/sensu",
    "user": "sensu",
    "password": "secret",
    "heartbeat": 30,
    "prefetch": 50,
    "ssl": {
      "cert_chain_file": "/etc/sensu/ssl/cert.pem",
      "private_key_file": "/etc/sensu/ssl/key.pem"
    }
  }
}
 

make sure above 3 files are placed in /etc/sensu/conf.d directory as shown below :

 

Step 5 : Import ssl & install plugins

Make directory & set permission

[root@client_sensu ~]# cd /etc/sensu/
[root@client_sensu ~]# mkdir ssl
[root@client_sensu ~]# chown -R sensu:sensu ssl/

Install some plugins :

[root@client_sensu ~]# sensu-install check-memory-percent
[root@client_sensu ~]# sensu-install -p check-memory-percent
[root@client_sensu ~]# sensu-install -p sensu-plugins-memory-checks
[root@client_sensu ~]# sensu-install -p sensu-plugins-cpu-checks
[root@client_sensu ~]# sensu-install -p sensu-plugins-systemd
[root@client_sensu ~]# sensu-install -p sensu-plugins-process-checks

Restart & enable all the services 

[root@client_sensu ~]# systemctl restart sensu-{client,server} redis
[root@client_sensu ~]# systemctl status sensu-{client,server} redis
[root@client_sensu ~]# systemctl enable sensu-{client,server} redis

Login to sensu-server – 192.168.33.47

Step 1: install the Epel-release

[root@sensu ~]# yum install epel-release -y

Install wget & vim too if you didn’t have :

[root@sensu ~]# yum install wget vim -y

Step 2: Insert the Erlang's repository file

Copy Paste the below lines in the file –

[root@sensu ~]# vim /etc/yum.repos.d/erlang.repo
 
[erlang-solutions]
name=CentOS $releasever - $basearch - Erlang Solutions
baseurl=https://packages.erlang-solutions.com/rpm/centos/7/$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.erlang-solutions.com/rpm/erlang_solutions.asc

Install erlang

[root@sensu ~]# yum install erlang -y

Step 3 : Install Sensu

Add repository first –

[root@sensu ~]# echo '[sensu]
name=sensu
baseurl=https://eol-repositories.sensuapp.org/yum/$releasever/$basearch/
gpgkey=https://eol-repositories.sensuapp.org/yum/pubkey.gpg
gpgcheck=1
enabled=1' | sudo tee /etc/yum.repos.d/sensu.repo

Now, Install Sensu, Redis & Rabbitmq –

[root@sensu ~]# yum install sensu -y
[root@sensu ~]# yum install redis -y
[root@sensu ~]# yum install https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.4/rabbitmq-server-3.8.4-1.el8.noarch.rpm -y

Step 4 : Install Sensu SSL Tool

[root@sensu ~]# wget http://docs.sensu.io/sensu-core/1.4/files/sensu_ssl_tool.tar
[root@sensu ~]# tar -xvf sensu_ssl_tool.tar
[root@sensu ~]# cd sensu_ssl_tool/
[root@sensu ~]# ./ssl_certs.sh generate
[root@sensu ~]# yum install openssl -y

Step 5 : Configure Rabbitmq

Stop rabbitmq service & Create configure file –

[root@sensu ~]# service rabbitmq-server stop
[root@sensu ~]# vim /etc/rabbitmq/rabbitmq.config

Copy Paste the below lines in the file –

[
{rabbit, [
{ssl_listeners, [5671]},
{ssl_options, [{cacertfile,"/etc/rabbitmq/ssl/cacert.pem"},
{certfile,"/etc/rabbitmq/ssl/cert.pem"},
{keyfile,"/etc/rabbitmq/ssl/key.pem"},
{versions, ['tlsv1.2']},
{ciphers, [{rsa,aes_256_cbc,sha256}]},
{verify,verify_peer},
{fail_if_no_peer_cert,true}]}
]}
].

Configuring ssl –

[root@sensu ~]# mkdir /etc/rabbitmq/ssl
[root@sensu ~]# cp sensu_ssl_tool/sensu_ca/cacert.pem /etc/rabbitmq/ssl/
[root@sensu ~]# cp ../server/cert.pem /etc/rabbitmq/ssl/
[root@sensu ~]# cp ../server/key.pem /etc/rabbitmq/ssl/

Restarting the rabbitmq service-

[root@sensu ~]# systemctl restart rabbitmq-server
[root@sensu ~]# systemctl enable rabbitmq-server

Installing net-tools & configuring rabbitmq service & set permissions :

[root@sensu ~]# yum install net-tools -y
[root@sensu ~]# netstat -tulnp
[root@sensu ~]# rabbitmqctl add_vhost /sensu
[root@sensu ~]# rabbitmqctl add_user sensu secret
[root@sensu ~]# rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"

set sensu permissions & make ssl directory in /etc/sensu copy files into it :

[root@sensu ~]# chown -R sensu:sensu /etc/sensu
[root@sensu ~]# cd /etc/sensu/
[root@sensu ~]# mkdir ssl
[root@sensu ~]# cd
[root@sensu ~]# cd sensu_ssl_tool/client/
[root@sensu ~]# cp cert.pem key.pem /etc/sensu/ssl/

Create sensu directory & set permission of it:

[root@sensu ~]# mkdir /sensu
[root@sensu ~]# chmod 777 /sensu

Step 6 : Now, Inserting some repositories :

*uchiwa.json –

[root@sensu ~]# echo '{
"sensu": [
{
"name": "sensu",
"host": "127.0.0.1",
"port": 4567
}
],
"uchiwa": {
"host": "0.0.0.0",
"port": 3000
}
}' |sudo tee /etc/sensu/uchiwa.json

*client.json –

[root@sensu ~]# cd /etc/sensu/conf.d
[root@sensu ~]# vim client.json

Copy Paste the below lines in the file –

{
  "client": {
    "name": "sensuserver",
    "address": "127.0.0.1",
    "subscriptions": [
      "server"
    ]
  }
}

*transport.json –

[root@sensu ~]# vim transport.json

Copy Paste the below lines in the file –

{
"transport": {
"name": "rabbitmq",
"reconnect_on_error": true
}
}

*rabbitmq.json –

[root@sensu ~]# vim rabbitmq.json

Copy Paste the below lines in the file –

{
"rabbitmq": {
"host": "127.0.0.1",
"port": 5671,
"vhost": "/sensu",
"user": "sensu",
"password": "secret",
"heartbeat": 30,
"prefetch": 50,
"ssl": {
"cert_chain_file": "/etc/sensu/ssl/cert.pem",
"private_key_file": "/etc/sensu/ssl/key.pem"
}
}
}

*api.json –

[root@sensu ~]# vim api.json

Copy Paste the below lines in the file –

{
  "api": {
    "host": "127.0.0.1",
    "bind": "0.0.0.0",
    "port": 4567
  }
}
 

*sensu_check.json –

[root@sensu ~]# vim sensu_check.json

Copy Paste the below lines in the file –

{
  "checks": {
    "check_mysql_running": {
     "type": "metric",
      "command": "check-process.rb -p mysql",
      "subscribers": [
        "production"
       ],
      "interval": 10,
      "handlers": ["logstash" , "file"]    
    },


    "check_memory": {
     "type": "metric",
      "command": "check-memory.rb  -w 300 -c 200 -p",
      "subscribers": [ "production" ],
      "interval": 10,
      "handlers": ["logstash" , "file"]
    },

    "check_sensu_running": {
     "type": "metric",
      "command": "check-process.rb -p sensu",
      "subscribers": [ "production" ],
      "interval": 10,
      "handlers": ["logstash" , "file"]
},


"check_memory_percentage": {
     "type": "metric",
      "command": "check-memory-percent.rb -w 79 -c 80",
      "subscribers": [ "production" ],
      "interval": 10,
      "handlers": ["logstash" , "file"]
},

  "check-cpu": {
      "command": "check-cpu.rb -w 10 -c 80",
      "subscribers": ["production"],
      "interval": 10, 
      "refresh": 10,
      "handlers": ["logstash" , "file"]

},
  
  "check-cpu_iowait": {
      "command": "check-cpu.rb --iowait  -w 20 -c 50",
      "subscribers": ["production"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["logstash" , "file"]
},


  "check-cpu_idle": {
      "command": "check-cpu.rb --idle   -w 20 -c 10",
      "subscribers": ["production"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["logstash" , "file"]
},


   "check-mariadb": {
      "command": "check-systemd.rb -s mariadb.service",
      "subscribers": ["production"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["logstash" , "file"]
},


  "check-redis": {
      "command": "check-systemd.rb -s redis.service",
      "subscribers": ["server"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["logstash" , "file"]
},



  "check-sensu_server": {
      "command": "check-systemd.rb -s sensu-server.service",
      "subscribers": ["server"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["logstash" , "file"]
},

  "check-sensu_client": {
      "command": "check-systemd.rb -s sensu-client.service",
      "subscribers": ["production", "server"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["logstash" , "file"]
},



  "check-sensu_api": {
      "command": "check-systemd.rb -s sensu-api.service",
      "subscribers": ["server"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["logstash" , "file"]


    }
  }
} 

*file_handler.json –

[root@sensu ~]# vim file_handler.json

Copy Paste the below lines in the file –

{
  "handlers": {
    "file": {
      "type": "pipe",
      "command": "/opt/sensu/embedded/bin/file.rb"
    }
  }
}

make sure above 6 files are placed in /etc/sensu/conf.d directory as shown below :

 

*file.rb

[root@sensu ~]# cd /opt/sensu/embedded/bin/
[root@sensu ~]# vim file.rb

Copy Paste the below lines in the file –

#!/usr/bin/env ruby

require 'rubygems'
require 'json'

# Read event data
event = JSON.parse(STDIN.read, :symbolize_names => true)
# Write the event data to a file
#file_name = "/tmp/sensu_#{event[:client][:name]}_#{event[:check][:name]}"
#file_name = "/tmp/sensu"
file_name = "/sensu/#{event[:check][:name]}"
reviews = event[:client]
check = event[:check]
File.open(file_name, 'a') do |file|
  file.write("#{event[:client][:name]} #{event[:client][:timestamp]} #{event[:check][:name]} #{event[:check][:output]}")
#  file.write("arun")
end

Step 7 : Export SSL

Export the ssl file to the client –

[root@sensu ~]# cd /etc/sensu/ssl/
[root@sensu ~]# scp * root@192.168.33.40:/etc/sensu/ssl

Step 8 : Install Uchiwa

Install uchiwa 

[root@sensu ~]# yum install uchiwa -y

add plugin for sensu :

[root@sensu ~]# sensu-install -p sensu-plugins-systemd

Restart & enable all the services of both Servers

[root@sensu ~]# systemctl restart sensu-{client,server,api} uchiwa redis rabbitmq-server
[root@sensu ~]# systemctl status sensu-{client,server,api} uchiwa redis rabbitmq-server
[root@sensu ~]# systemctl enable sensu-{client,server,api} redis rabbitmq-server

Step 9 : Open Browser

Open your browser & type the url with port “3000”  as shown below

http://192.168.33.47:3000/

You may also like...

Leave a Reply

Your email address will not be published.