Code Snippet

Just another Code Snippet site

[How-To] Zabbix

Run Zabbix from Docker containers : https://www.zabbix.com/documentation/4.0/manual/installation/containers


 


15 thoughts on “[How-To] Zabbix

  • Olivier says:

    Zabbix – Add Slack notif :

    Create a Slack webhook : https://custdev3.slack.com/apps/manage/custom-integrations

    Copy the following script to /usr/lib/zabbix/alertscripts/slack.sh

    #!/bin/bash
    
    # Slack incoming web-hook URL and user name
    zabbix_host=my_zabbix_host.lan
    webhook_url='https://hooks.slack.com/services/.../.../...'
    
    severity=$1
    host=$2
    trigger=$3
    triggerId=$4
    eventId=$5
    eventStatus=$6
    
    ## ###################################### ##
    ##  Slack notif message
    ## ###################################### ##
    case $eventStatus in
            PROBLEM)
                message="[PROBLEM] $trigger"
                ;;
            RECOVERY)
                message="[RECOVERY] $trigger"
                severity="Information"
                ;;
            RESOLVED)
                message="[RESOLVED] $trigger"
                severity="Information"
                ;;
            *)
                message="[$severity] $trigger"
    esac
    
    ## ###################################### ##
    ##  Slack notif color
    ## ###################################### ##
    case $severity in
            Information)
                color=good
                ;;
             
            Warning)
                color=warning
                ;;
             
            Average)
                color=warning
                ;;
            High)
                color=danger
                message="$message - High"
                ;;
            Disaster)
                color=danger
                message="$message - Disaster !!!"
                ;;
             
            *)
                color=#333333
     esac
     
     
    eventViewUrl="http://${zabbix_host}/zabbix.php?action=acknowledge.edit&eventids%5B0%5D=${eventId}"
    triggerViewUrl="http://${zabbix_host}/zabbix.php?action=problem.view&filter_triggerids%5B%5D=${triggerId}&filter_set=1"
    
    message="${message}\n<${triggerViewUrl}|See Trigger> | <${eventViewUrl}|See Event>"
     
    CONTENT="{'username':'Zabbix@$host', 'attachments': [{'color': '$color', 'text':'$message'}]}"
    
    curl -X POST -H 'Content-type: application/json' --data "$CONTENT" $webhook_url
    

    In Zabbix webapp, create a new Action (Configuration > Action > Create) with:
    New Operation:
    – Operation Type = Remote Command
    – Target = Current Host
    – Type = Custom Script
    – Execute On = Zabbix Server
    – Commands = /usr/lib/zabbix/alertscripts/slack.sh “{TRIGGER.SEVERITY}” “{HOST.HOST}” “{TRIGGER.NAME}” “{TRIGGER.ID}” “{EVENT.ID}” “{EVENT.STATUS}”

    Do the same for Recovery if needed

  • Olivier says:

    Backup

  • Olivier says:

    The default user is “Admin” and the password is “zabbix”

  • UserParameter

    In the /etc/zabbix/zabbix_agentd.conf :

    UserParameter=myKey1.myKey2,echo "A"
    

    In the UI, create a new item with Key = myKey1.myKey2

  • For Windows, download and unzip archive : https://www.zabbix.com/download

    Run as administrator :

    C:\...\bin\zabbix_agentd.exe --config C:\...\conf\zabbix_agentd.conf --install
    
    C:\...\bin\zabbix_agentd.exe --config C:\...\conf\zabbix_agentd.conf --start
    

    See also : https://www.tecmint.com/install-zabbix-agent-and-add-windows-host-to-zabbix-monioring/

  • Load a backup :
    From MySQL container :

    mysql -u ZABBIX_USER -p ZABBIX_DB_NAME < /var/lib/backup/backup/zabbix_cfg__20200626-0729_db-mysql-4.0.3.sql
    
  • Backup docker DB :
    Mount a shared drived into the container (for example into /var/lib/backup/)

    Download the backup script from : https://github.com/maxhq/zabbix-backup

    Create a shell script :

    LOG_FILE="${ROOT_DIR}/logs/zabbix_backup_`date +%Y-%m-%d`.log"
    
    ZABBIX_DB_CONTAINER=""
    ZABBIX_DB_USERNAME=""
    ZABBIX_DB_PASSWORD=""
    
    docker exec -i $ZABBIX_DB_CONTAINER bash -c "/var/lib/backup/zabbix-dump -u $ZABBIX_DB_USERNAME -p $ZABBIX_DB_PASSWORD -o /var/lib/backup/backup -r 10" 2>&1 | tee --append "${LOG_FILE}" ; test ${PIPESTATUS[0]} -eq 0
    

    Add a cron :

     
    0 20 * * * /path/to/backupZabbixDockerDatabase.sh
    
  • Docker compose :

    version: '2'
    
    services:
    
      server:
        image: zabbix/zabbix-server-mysql:alpine-4.4.0
        environment:
          DB_SERVER_HOST: mysql-server
          MYSQL_DATABASE: zabbix
          MYSQL_PASSWORD: beV2i4C4
          MYSQL_ROOT_PASSWORD: r44VygK9
          MYSQL_USER: zabbix
          ZBX_VALUECACHESIZE: 1000M
          ZBX_CACHESIZE: 1000M
        volumes:
          - /opt/app/zabbix/scripts:/usr/lib/zabbix/alertscripts
        links:
          - mysql:mysql-server
        ports:
          - 10051:10051/tcp
    
      nginx:
        image: zabbix/zabbix-web-nginx-mysql:alpine-4.4.0
        environment:
          DB_SERVER_HOST: mysql-server
          MYSQL_DATABASE: zabbix
          MYSQL_PASSWORD: beV2i4C4
          #MYSQL_ROOT_PASSWORD: r44VygK9
          MYSQL_USER: zabbix
          PHP_TZ: Europe/Brussels
        links:
          - server:zabbix-server
          - mysql:mysql-server
        ports:
          - 8888:80/tcp
    
      mysql:
        image: mysql:5.7
        environment:
          MYSQL_DATABASE: zabbix
          MYSQL_ROOT_PASSWORD: r44VygK9
          MYSQL_USER: zabbix
          MYSQL_PASSWORD: beV2i4C4
        ports:
          - 3306:3306/tcp
        volumes:
          - /opt/app/zabbix/mysql:/var/lib/mysql
          - /opt/app/zabbix/backup:/var/lib/backup
    
    
  • Error in the logs :

    cannot set resource limit: [13] Permission denied
    

    Short workaround, disable selinux (not recommended)

    setenforce 0
    

    See https://catonrug.blogspot.com/2018/02/cannot-set-resource-limit-13-permission-denied.html

  • For Ubuntu, the agent config must be updated with

    Server=0.0.0.0/0,10.2.2.197,::/0,<SERVER_IP>
    

Leave a Reply to OLIVIER COMBE Cancel reply

Your email address will not be published. Required fields are marked *