Ad Widget

Collapse

checks_external.c correction

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • testos
    Member
    • Apr 2007
    • 85

    #1

    checks_external.c correction

    I'm working for several weeks in a few external scripts for:
    - restart zabbix agent in windows/linux machines from zabbix server
    - stop zabbix agent in windows/linux machines from zabbix server
    - start zabbix agent in windows/linux machines from zabbix server
    - status zabbix agent in windows/linux machines from zabbix server
    - copy a new start/stop/restart zabbix agent script in windows/linux machines from zabbix server
    - remotely zabbix agent installation in windows/linux machines from zabbix server

    I discovered that checks_external.c returned nothing with scripts containing instructions to creating child processes within as sleep, scp, ssh, while, and so on.
    checks_external.c use popen() function for "open'' a process by creating a bidirectional pipe, forking, and invoking the shell, but it don't wait for the last child spawned by the parent script.
    I patched checks_external.c adding wait(NULL); instruction just below popen and now everything works perfectly.

    PHP Code:
        if (NULL == (fp popen(cmd"r"))) 
        {
            
    zbx_snprintf(error,MAX_STRING_LEN-1,"External check [%s] is not supported, failed execution"item->key);
            
    zabbix_logLOG_LEVEL_DEBUG"%s"error);
            
    SET_STR_RESULT(resultstrdup(error));
            return 
    NOTSUPPORTED;
        }
        
    wait(NULL);
        
    /* we only care about the first line */ 
Working...