Ad Widget

Collapse

how to add own scripts and add alerting on specific behaviors?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoNomad
    Junior Member
    • Oct 2023
    • 1

    #1

    how to add own scripts and add alerting on specific behaviors?

    Hey everyone,

    short version:
    how to add own scripts and add alerting on specific behaviors?

    long version:
    I have written a script that monitors PHP-FPM pools, especially the processes - In detail it checks on execution or in real-time (loop) the php log file for "server reached pm.max_children setting​".

    I want to use this script with Zabbix to get an alarm when the script reports occurence.

    Preferably an action should first try (I also have a script for this) to raise the maximum possible processes before an alarm comes. If the script cant raise it, a alarm comes up.

    How can I configure something like this in Zabbix? It is enough for me to get the right documentation, because I can't find anything about this. Especially alarming on specific script notifications.

    Best regards
    NeoNomad
  • Sosisoft
    Junior Member
    • Oct 2023
    • 4

    #2
    Hello everyone,
    I have two problems with alert script located in /usr/lib/zabbix/alertscripts:
    1.
    Code:
    #!/bin/bash
    
    sendto="$1"
    message="$2"
    username="sender"
    password="some pwd"
    provider="Orange"
    directory=$(pwd)
    
    # JSON data
    data="{"auth":{"username":"$username","pass word":"$password"},"provider":"$provider",\ "number":"$sendto","content":"$message" }"
    
    response=$(curl -sS -X POST [URL]http://smsserver/goip/sendsms/[/URL] -H "Content-Type: application/json" -d "$data")
    
    log_file="sms_server_response.log"
    timestamp=$(date +"%d.%m.%Y %H:%M:%S")
    
    echo "$timestamp $response" >> "$directory/$log_file"​
    I can call this script with Media type/Test and it works fine(sends SMS over SMS server) if last row echo.... is commented. If not I got permission denied to write in log, but SMS is sent . Owner of -R /usr/lib/zabbix is zabbix:zabbix. So this is smaller problem

    2. My script is not called even is in problems mentioned action trigger
    18.10.2023 02:00:33 Admin (Zabbix Administrator) SMS_notify Sent
    18.10.2023 02:00:32
    In media Type I have created new type script with name SMS_notify and with alertscript mentioned in 1.
    Admin has defined only one Media Type - SMS_notify

    My script is never called and I find nothing in log files.

    OS is Suse SLE15 SP3.

    Please help.
    Last edited by Sosisoft; 18-10-2023, 15:21.

    Comment

    • tim.mooney
      Senior Member
      • Dec 2012
      • 1427

      #3
      Originally posted by NeoNomad

      short version:
      how to add own scripts and add alerting on specific behaviors?
      Custom items and script items are called "User Parameters", and they are discussed in the Items section of the Configuration chapter of the manual: https://www.zabbix.com/documentation...userparameters

      What you are doing is creating a custom item, including making up a name for the item key, e.g. neonomad.php.max_children_reached. Once you have your item defined and collecting data, then writing a trigger for it is just like writing a trigger for any other item that Zabbix can collect.

      Originally posted by NeoNomad
      long version:
      I have written a script that monitors PHP-FPM pools, especially the processes - In detail it checks on execution or in real-time (loop) the php log file for "server reached pm.max_children setting​".

      I want to use this script with Zabbix to get an alarm when the script reports occurence.

      Preferably an action should first try (I also have a script for this) to raise the maximum possible processes before an alarm comes. If the script cant raise it, a alarm comes up.
      You're welcome to proceed with your custom script user parameter for monitoring your pool, but there are existing methods for checking whether max_children has been reached. If you enable the pm.status_path for the pool (see the section of the pool config), you can just query a URL and get whether "max children reached" has happened and what your maximum number of active processes has been:

      Code:
      $wget -q 'https://vhost.name.here/www-status' -O -
      pool:                 www
      process manager:      dynamic
      start time:           29/Jul/2023:00:25:09 -0500
      start since:          7046071
      accepted conn:        5610039
      listen queue:         0
      max listen queue:     2
      listen queue len:     128
      idle processes:       9
      active processes:     1
      total processes:      10
      max active processes: 10
      max children reached: 0
      slow requests:        0
      With that, you could use a web check and some filtering to get 'max children reached' and other process settings (look up aggregate items in the configuration setting, you could fetch this URL once and get multiple different data items from it).

      If you do some web searching for Zabbix templates, I think you'll find that there's already a template you can import on your server that does most of the Zabbix setup for monitoring PHP-FPM worker pools. https://www.zabbix.com/integrations/phpfpm

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #4
        aaand.. log file can be read with log or logrt item, no need for custom scripts....

        Comment

        Working...