Rundeck – Run Docker container

Posted: January 4, 2019 in docker, RunDeck

In previous article we configured email monitoring by Zabbix, in this one we’ll schedule python script for sending data to Zabbix, to be run from Docker container
Docker image is created from this file, script will be copied to Docker container, and zabbix agent will be installed

FROM python:3.7.2-stretch

RUN wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1%2Bbionic_all.deb apt-get update -y && apt-get install zabbix-agent -y && mkdir /email_parsing

WORKDIR /email/parsing

COPY start.py .

ENTRYPOINT ["python", "./start.py"]

Create container from image:

docker build . -t zabbix/parse_email:1.0.0

Install Docker on Rundeck, and add Rundeck user to Docker group

usermod -a -G docker rundeck
systemctl restart docker
systemctl restart rundeckd

Create Rundeck job-Local Command

2.PNG

Create password vault for mailbox – see this post for reference and specify it as parameter for script,container will be deleted after every run

docker run --rm zabbix/parse_email:1.0.0 "-password" ${option.mailboxpassword}

Dockerizing Zabbix trapper

We can create docker image for zabbix trapper commands

Dockerfile:

FROM ubuntu:latest

RUN apt-get update -y && apt-get install wget -y && wget http://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-1%2Bbionic_all.deb && apt-get install zabbix-agent -y && mkdir /zabbix_sender

WORKDIR /zabbix_sender

COPY . .

ENTRYPOINT ["./start.sh"]

start.sh:

#!/bin/bash


while test -n "$1"; do
    case "$1" in
      -j|-job)
          job_name=$2
          shift 2
         ;;
    esac
done

#echo $job_name

if [ "$job_name" == "some_job" ]; then

   zabbix_sender -z zabbix_host -s rundeck -k job_status[job_name] -o "job $job_name failed" -vv

i created docker container with tag “zabbix_sender”, it takes job name as parameter

If using remote registry add step for login to it:

echo password | docker login --username username --password-stdin registry_name

Now, we can add Error handler in Rundeck, so if job fails,Zabbix alert will be triggered, under command click “cog” icon and select “Add error handler”

1.PNG

click Command or Local Command and add following line:

docker run --rm zabbix_sender -job ${option.job_name}

job name is declared as Rundeck option

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s