Rundeck with Zabbix

Zabbix_Rundeck - CPU-Utilization

In this project, we are going to monitor the CPU Process in Linux and windows machines Using Zabbix and Zabbix to trigger the Rundeck to check the CPU process and restart the service, in case unwanted service is running on Zabbix-agent. This issue creates a Jira ticket and adds a custom field to mention the issue type through a script.

1. Zabbix:

1.Add Host in Zabbix server like this,

For Linux:

For Windows:

3.Create an Action for CPU-Utilization and add the condition.


Script Location: /usr/lib/zabbix/externalscript/cpu-utilization.sh

Command: hostname={HOST.NAME} eventid={EVENT.ID} bash /usr/lib/zabbix/externalscript/cpu-utilization.sh


1.Create a Project for CPU-Utilization:(Linux & Windows)


2 .  Linux Script                                                         

[email protected]@

TOPPROCESS=$(top -b -n 1 | sed 1,6d | sed -n 2p)

TOPPID=$(echo "$TOPPROCESS" | awk '{print $1}')

TOPNAME=$(echo "$TOPPROCESS" | awk '{print $12}')

echo "$nodeostype"

echo "$TOPPROCESS"

echo "$TOPPID"

echo "$TOPNAME"

if [ "$nodeostype" == "centos" ]; then

  echo "This is linux machine 192.168.4.115"

  if [ "$TOPNAME" = "sshd" ]

    then

        systemctl status sshd

        var="$TOPNAME"

        echo "$var"

        #sleep 10

        echo "this is $TOPNAME"

  elif [ "$TOPNAME" = "httpd" ]

    then

        systemctl restart httpd.service

        var="$TOPNAME"

        echo "$var"

        echo "this is $TOPNAME"

  elif [ "$TOPNAME" = "java" ]

    then

        #kill -9 $TOPPID

        var="$TOPNAME"

        echo "$var"

        echo "this is $TOPNAME"

  elif [ "$TOPNAME" = "mysqld" ]

    then

        systemctl restart mariadb

        var="$TOPNAME"

        echo "$var"

        echo "this is $TOPNAME"

sleep 10

  elif [ "$TOPNAME" = "python" ]

    then

        #kill -9 $TOPPID

        var="$TOPNAME"

        echo "$var"

        echo "this is $TOPNAME"

  elif [ "$TOPNAME" = "zabbix_agentd" ]

    then

        systemctl restart zabbix-agent

        var="$TOPNAME"

        echo "$var"

        echo "this is $TOPNAME"

sleep 10

  else

     echo "not for this"

      var="$TOPNAME"

      echo "$var"

      echo "this is $TOPNAME"

#    java -jar /var/lib/rundeck/atlassian-cli-9.2.0/lib/acli-9.2.0.jar --server http://192.168.4.115:8080 --user "aiops" --password "zippyops" --action createIssue --project "CPU" --type "Task" --summary "task2"

  fi

fi

echo "var=$var"

3 .  Windows Script                                                        

#!/bin/bash

$nodehostname='windowsnode'

$servername='centosnode'

$filename='messages'

$path='/var/log'

$directory='archive'

$find="$path/$filename"

$path1='C:/'

$source="$path1/$directory"

$dest='C:/backupdirectory/'

echo "$nodehostname"

echo "$servername"

echo "$filename"

echo "$path"

echo "$directory"

echo "$find"

echo "$source"

echo "$dest"

if("$nodehostname" -eq "$servername"){

 if  (Test-Path -path $source)

  {

    echo "$source already exists"

  }

  else

  {

    echo "$source not found"

    md $source

    echo "successfully $source was created"

  }

 if  (Test-Path -path $find)

  {

 if  (Test-Path -path $find)

  {

    Copy-Item -Path "$find" -Destination "$source/$filename" -Force

    $files = Get-ChildItem -Path $source -File $filename

    Add-Type -assembly 'system.io.compression.filesystem'

    foreach ($file in $files) {

    $folder = $file.directoryname | Split-Path -Leaf

    If (!(Test-Path $dest$folder.zip)){New-Item $dest$folder.zip -ItemType file}

    $zip = [io.compression.zipfile]::Open("$dest$folder.zip",'Update')

    [IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip,$file.FullName,$file.name)

    $zip.dispose()

    Remove-Item -path "$path1/$directory" -Force -Recurse

    echo "Archived is success"

    echo "This is your Archived File $dest/$directory"

    $var1="True"

    echo "var1=$var1"

    }

  }else{

    echo "$filename not found"

    $var1="False"

    echo "var1=$var1"

  }

  echo " This is Windows machine"

    $var2="True"

    echo "var2=$var2"

}else{

  echo "Excution is not for this machine"

  $var2="False"

}

echo "var2=$var2"

echo "var1=$var1"

  1. Mail script

For Linux:

#!/bin/bash

var=1

servername=centosnode

status=Approved

path=/var/log

filename=messages

[email protected]

file="$path/$filename"

if [ $servername == centosnode ]; then

  if [[ $var == 0 || $var == True ]]; then

    if [ $status == Approved ]; then

      if [ -d "${path}" ]; then

        if [ -f "$file" ]; then

          echo "This is your Archived File messages is success" | mail -s "Centos node Log Archival is done" $mail

        else

          echo "$file not found" | mail -s "Centos node Log File Not Found" $mail

        fi

      else

            echo "$path is not found" | mail -s "Centos node Log filepath is Not Found" $mail

      fi

    else

      if [ $status == Rejected ]; then

        echo "The issue $issue was rejected" | mail -s "Centos node issuse was Rejected" $mail

      fi

    fi

  elif [[ $var == 1 || $var == False ]]; then

     echo "Not found in the specfied server $servername"

  else

     echo "Execution is not for Centos machine"

  fi

elif [ $servername == ubuntunode ]; then

  if [[ $var == 0 || $var == True ]]; then

    if [ $status == Approved ]; then

      if [ -d "${path}" ]; then

        if [ -f "$file" ]; then

          echo "This is your Archived File messages is success" | mail -s "Ubuntu node Log Archival is done" $mail

        else

          echo "$file not found" | mail -s "Ubuntu node Log File Not Found" $mail

        fi

      else

            echo "$path is not found" | mail -s "Ubuntu node Log filepath is Not Found" $mail

      fi

    else

      if [ $status == Rejected ]; then

        echo "The issue $issue was rejected" | mail -s "Ubuntu node issuse was Rejected" $mail

      fi

    fi

  elif [[ $var == 1 || $var == False ]]; then

     echo "Not found in the specfied server $servername"

  else

     echo "Execution is not for Ubuntu machine"

  fi

fi

For Windows:

#!/bin/bash

var2=False

var1=

servername=centosnode

status=Approved

filename=messages

[email protected]

if [ $servername == windowsnode ]; then

  if [ $var2 == True ]; then

    if [ $status == Approved ]; then

      if [ $var1 == True ]; then

        echo "This is your Archived File messages is success" | mail -s "Windows node log Archival process done" $mail

      else

        echo "your $filename not found" | mail -s "Windows node Log Archival Not done" $mail

      fi

    else

      if [ $status == Rejected ]; then

        echo "The issue $issue was rejected" | mail -s "Windows Log archival was Rejected" $mail

      fi

    fi

  else

    echo "Not found in the specfied server $servername"  | mail -s "Windows Log archival not done" $mail

  fi

else

  echo "Execution is not for Windows machine"  | mail -s "Windows Log archival Not Done" $mail

fi


5.Integration script

#!/bin/bash

echo "$hostname"

echo "$eventid"

if [ "$hostname" == "centos_node" ]; then

  curl \

  -D - \

  -X "POST" -H "Accept: application/json" \

  -H "Content-Type: application/json" \

  -H "X-Rundeck-Auth-Token: BRaq7hklM9OxbHL5geLS8hG6AkJASbed" \

  -d "{\"argString\":\"-arg1 $hostname -arg2 $eventid \"}" \

  "http://192.168.5.116:4440/api/16/job/03bcc87e-9613-48d7-8fb6-d1f5ebb5e33f/executions"

  echo "this is Centos machine"

elif [ "$hostname" == "ubuntu_node" ]; then

  curl \

  -D - \

  -X "POST" -H "Accept: application/json" \

  -H "Content-Type: application/json" \

  -H "X-Rundeck-Auth-Token: BRaq7hklM9OxbHL5geLS8hG6AkJASbed" \

  -d "{\"argString\":\"-arg1 $hostname -arg2 $eventid \"}" \

  "http://192.168.5.116:4440/api/16/job/7b8cc043-baed-4c35-a809-b86dbc5cc531/executions"

  echo "this is Ubuntu machine"

elif [ "$hostname" == "windows_node" ]; then

  curl \

  -D - \

  -X "POST" -H "Accept: application/json" \

  -H "Content-Type: application/json" \

  -H "X-Rundeck-Auth-Token: BRaq7hklM9OxbHL5geLS8hG6AkJASbed" \

  -d "{\"argString\":\"-arg1 $hostname -arg2 $eventid \"}" \

  "http://192.168.5.116:4440/api/16/job/cff73bae-fa0c-4bab-a570-5693293ce671/executions"

  echo "this is Windows machine"

fi



Relevant Blogs:

Rundeck with Nagios Rundeck - Adding nodes 

Zabbix Installation and configuration 

What is AWS Detective and How it Works?

Docker build in pipeline  

Recent Comments

No comments

Leave a Comment