Pandora FMS Community

how to execute a script in a module

dan2kg · 29 jun 2012, 13:08 · 5 mensajes · 68 visitas

  1. Inicio del debate

    Hello, I am trying to run a script that returns a value of either 0 when a service is not running and 1 when it's running however i am a little lost as to how to go about it. Currently i have module that returns a string value with the status of a service like tentacle. Below is the module.

    module_begin
    module_name tent_status
    module_type generic_data_string
    module_interval 1
    module_exec service tentacle_serverd status
    module_description Status of tentacle Server
    module_end
    

    however this doesn't help me because when a process restarts it changes PIDs hence making it difficult to set a critical/warning status for it.  I hence wrote a shellscript that returns a numerical value 1 if the service status contains a string like "is running" and 0 if it doesn't contain it.

    
    #! /bin/bash
    
    serVar=`service tentacle_serverd status`
    statVar="is running"
    if [[ "$serVar" == *"$statVar"* ]]
            then echo 1
            else echo 0
    fi
    

    I was wondering which directory i would have to place it so that i can run it through a module. Or am i going about it the wrong way. For example. module_begin module_name tent_status module_type generic_data module_interval 1 module_exec ~/Documents/tentacle.sh module_description check status of tentacle module_end Thanks for any help you can give.

  2. You can execute this module:

    module_begin
    module_name tent_status
    module_type generic_proc
    module_interval 1
    module_exec ps axu | grep tentacle_server | grep -v grep | wc -l
    module_description Status of tentacle Server
    module_end
    

    If value is 0, then the module is going to critical. Values grater than 0 return normal status. Regards.

  3. Thanks Luismi.....Works like a charm. I am assuming this works for other processes as well.

  4. Hi dan2kg, Remember in Windows systems you could use this module:

    
    module_begin
    module_name tent_status
    module_type generic_proc
    module_interval 1
    module_proc nameproccess.exe
    module_description Status of tentacle Server
    module_end
    

    Or

    
    module_service nameservice
    

    Cheers.

  5. module_exec ~/Documents/tentacle.sh

    bash evaluates ~/ based on the user, so module_exec has to pass this to bash and then it'll evaluate as the user the agent runs as.  So if the agent is configured to run as user 'pandora' with home /usr/share/pandora, ~/Documents = /usr/share/pandora/Documents tbh I don't trust all that; if you have a problem, first give it an absolute path and try. Just a thought.

Entra en tu cuenta para publicar.