Advertisement
Guest User

Zabbix Patch

a guest
Dec 3rd, 2013
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.89 KB | None | 0 0
  1. Description: Allows to run user scripts on a host's proxy
  2. With this new feature a new option appears on the frontend allowing
  3. to set up scripts for runing on a host's proxy.
  4.  .
  5.  zabbix (1:2.0.9-1+0.1) UNRELEASED; urgency=low
  6.  .
  7.    * Non-maintainer upload.
  8.    * Adding run in proxy feature
  9. Author: Spotflux | Juan Pablo Daniel Borgna <jpdborgna@spotflux.com>
  10.  
  11. ---
  12. The information above should follow the Patch Tagging Guidelines, please
  13. checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
  14. are templates for supplementary fields that you might want to add:
  15.  
  16. Origin: <vendor|upstream|other>, <url of original patch>
  17. Bug: <url in upstream bugtracker>
  18. Bug-Debian: http://bugs.debian.org/<bugnumber>
  19. Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
  20. Forwarded: <no|not-needed|url proving that it has been forwarded>
  21. Reviewed-By: <name and email of someone who approved the patch>
  22. Last-Update: <YYYY-MM-DD>
  23.  
  24. Index: zabbix-2.0.9/include/common.h
  25. ===================================================================
  26. --- zabbix-2.0.9.orig/include/common.h  2013-10-12 13:51:42.000000000 +0000
  27. +++ zabbix-2.0.9/include/common.h   2013-10-18 03:31:40.841680400 +0000
  28. @@ -682,6 +682,7 @@
  29.  
  30.  #define ZBX_SCRIPT_EXECUTE_ON_AGENT    0
  31.  #define ZBX_SCRIPT_EXECUTE_ON_SERVER   1
  32. +#define ZBX_SCRIPT_EXECUTE_ON_PROXY    2
  33.  
  34.  #define POLLER_DELAY       5
  35.  #define DISCOVERER_DELAY   60
  36. Index: zabbix-2.0.9/frontends/php/scripts.php
  37. ===================================================================
  38. --- zabbix-2.0.9.orig/frontends/php/scripts.php 2013-10-12 13:51:53.000000000 +0000
  39. +++ zabbix-2.0.9/frontends/php/scripts.php  2013-10-18 03:31:40.841680400 +0000
  40. @@ -32,7 +32,7 @@
  41.     'scripts' =>            array(T_ZBX_INT, O_OPT, P_SYS,          DB_ID,      null),
  42.     'name' =>               array(T_ZBX_STR, O_OPT, null,           NOT_EMPTY,  'isset({save})'),
  43.     'type' =>               array(T_ZBX_INT, O_OPT, null,           IN('0,1'),  'isset({save})'),
  44. -   'execute_on' =>         array(T_ZBX_INT, O_OPT, null,           IN('0,1'),  'isset({save})&&{type}=='.ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT),
  45. +   'execute_on' =>         array(T_ZBX_INT, O_OPT, null,           IN('0,1,2'),    'isset({save})&&{type}=='.ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT),
  46.     'command' =>            array(T_ZBX_STR, O_OPT, null,           null,       'isset({save})'),
  47.     'commandipmi' =>        array(T_ZBX_STR, O_OPT, null,           null,       'isset({save})'),
  48.     'description' =>        array(T_ZBX_STR, O_OPT, null,           null,       'isset({save})'),
  49. Index: zabbix-2.0.9/frontends/php/popup.php
  50. ===================================================================
  51. --- zabbix-2.0.9.orig/frontends/php/popup.php   2013-10-12 13:51:53.000000000 +0000
  52. +++ zabbix-2.0.9/frontends/php/popup.php    2013-10-18 03:31:40.841680400 +0000
  53. @@ -1858,6 +1858,9 @@
  54.                 case ZBX_SCRIPT_EXECUTE_ON_SERVER:
  55.                     $scriptExecuteOn = _('Server');
  56.                     break;
  57. +               case ZBX_SCRIPT_EXECUTE_ON_PROXY:
  58. +                   $scriptExecuteOn = _('Proxy');
  59. +                   break;
  60.             }
  61.         }
  62.         else {
  63. Index: zabbix-2.0.9/frontends/php/include/defines.inc.php
  64. ===================================================================
  65. --- zabbix-2.0.9.orig/frontends/php/include/defines.inc.php 2013-10-18 03:31:06.917626992 +0000
  66. +++ zabbix-2.0.9/frontends/php/include/defines.inc.php  2013-10-18 03:31:40.841680400 +0000
  67. @@ -61,6 +61,7 @@
  68.  define('ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT',    4);
  69.  
  70.  define('ZBX_SCRIPT_EXECUTE_ON_AGENT',  0);
  71. +define('ZBX_SCRIPT_EXECUTE_ON_PROXY',  2);
  72.  define('ZBX_SCRIPT_EXECUTE_ON_SERVER', 1);
  73.  
  74.  define('ZBX_FLAG_DISCOVERY_NORMAL',        0x0); // a normal item
  75. Index: zabbix-2.0.9/frontends/php/include/views/administration.script.edit.php
  76. ===================================================================
  77. --- zabbix-2.0.9.orig/frontends/php/include/views/administration.script.edit.php    2013-10-12 13:51:49.000000000 +0000
  78. +++ zabbix-2.0.9/frontends/php/include/views/administration.script.edit.php 2013-10-18 03:31:40.841680400 +0000
  79. @@ -55,6 +55,7 @@
  80.  $typeRB->makeVertical();
  81.  $typeRB->addValue(_('Zabbix agent'), ZBX_SCRIPT_EXECUTE_ON_AGENT);
  82.  $typeRB->addValue(_('Zabbix server'), ZBX_SCRIPT_EXECUTE_ON_SERVER);
  83. +$typeRB->addValue(_('Zabbix proxy'), ZBX_SCRIPT_EXECUTE_ON_PROXY);
  84.  $scriptTab->addRow(_('Execute on'), new CDiv($typeRB, 'objectgroup inlineblock border_dotted ui-corner-all'), $data['type'] == ZBX_SCRIPT_TYPE_IPMI);
  85.  
  86.  // command
  87. Index: zabbix-2.0.9/frontends/php/include/views/administration.script.list.php
  88. ===================================================================
  89. --- zabbix-2.0.9.orig/frontends/php/include/views/administration.script.list.php    2013-10-12 13:51:49.000000000 +0000
  90. +++ zabbix-2.0.9/frontends/php/include/views/administration.script.list.php 2013-10-18 03:31:40.841680400 +0000
  91. @@ -66,6 +66,9 @@
  92.             case ZBX_SCRIPT_EXECUTE_ON_SERVER:
  93.                 $scriptExecuteOn = _('Server');
  94.                 break;
  95. +           case ZBX_SCRIPT_EXECUTE_ON_PROXY:
  96. +               $scriptExecuteOn = _('Proxy');
  97. +               break;
  98.         }
  99.     }
  100.     else {
  101. Index: zabbix-2.0.9/frontends/php/include/views/configuration.action.edit.php
  102. ===================================================================
  103. --- zabbix-2.0.9.orig/frontends/php/include/views/configuration.action.edit.php 2013-10-12 13:51:49.000000000 +0000
  104. +++ zabbix-2.0.9/frontends/php/include/views/configuration.action.edit.php  2013-10-18 03:31:40.841680400 +0000
  105. @@ -661,6 +661,7 @@
  106.             $executeOnRadioButton->makeVertical();
  107.             $executeOnRadioButton->addValue(SPACE._('Zabbix agent').SPACE, ZBX_SCRIPT_EXECUTE_ON_AGENT);
  108.             $executeOnRadioButton->addValue(SPACE._('Zabbix server').SPACE, ZBX_SCRIPT_EXECUTE_ON_SERVER);
  109. +           $executeOnRadioButton->addValue(SPACE._('Zabbix proxy').SPACE, ZBX_SCRIPT_EXECUTE_ON_PROXY);
  110.             $newOperationsTable->addRow(array(_('Execute on'), new CDiv($executeOnRadioButton, 'objectgroup border_dotted ui-corner-all inlineblock')), 'class_opcommand_execute_on hidden indent_both');
  111.  
  112.             // ssh
  113. Index: zabbix-2.0.9/src/zabbix_server/scripts.c
  114. ===================================================================
  115. --- zabbix-2.0.9.orig/src/zabbix_server/scripts.c   2013-10-12 13:51:44.000000000 +0000
  116. +++ zabbix-2.0.9/src/zabbix_server/scripts.c    2013-10-18 03:31:40.841680400 +0000
  117. @@ -93,6 +93,44 @@
  118.     return ret;
  119.  }
  120.  
  121. +static int zbx_execute_script_on_proxy(DC_HOST *host, const char *command, char **result,
  122. +       char *error, size_t max_error_len)
  123. +{
  124. +   const char  *__function_name = "zbx_execute_script_on_proxy";
  125. +   int ret = FAIL;
  126. +    DB_RESULT   db_result;
  127. +    DB_ROW      db_row;
  128. +    DC_HOST     proxy;
  129. +
  130. +   zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
  131. +
  132. +    /* query the agent running on the proxy host */
  133. +    db_result = DBselect("select hostid from hosts where host = ( select host from hosts where hostid=\
  134. +        ( select proxy_hostid from hosts where hostid = " ZBX_FS_UI64 ")) and status != 5", host->hostid);
  135. +
  136. +    if (NULL != (db_row = DBfetch(db_result)))
  137. +    {
  138. +        memset(&proxy, 0, sizeof(proxy));
  139. +        ZBX_DBROW2UINT64(proxy.hostid, db_row[0]);
  140. +    }
  141. +    DBfree_result(db_result);
  142. +  
  143. +
  144. +    if ((0 == proxy.hostid) || (SUCCEED != DCget_host_by_hostid(&proxy, proxy.hostid)))
  145. +    {
  146. +        zbx_snprintf(error, sizeof(error), "Unknown Proxy ID [" ZBX_FS_UI64 "] for Host ID [" ZBX_FS_UI64 "]",
  147. +            proxy.hostid , host -> hostid);
  148. +        goto fail;
  149. +    }
  150. +
  151. +
  152. +   ret = zbx_execute_script_on_agent(&proxy,command,result,error,max_error_len);
  153. +fail:
  154. +    zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));
  155. +
  156. +    return ret;
  157. +}
  158. +
  159.  #ifdef HAVE_OPENIPMI
  160.  static int zbx_execute_ipmi_command(DC_HOST *host, const char *command, char *error, size_t max_error_len)
  161.  {
  162. @@ -346,6 +384,10 @@
  163.                     ret = zbx_execute(script->command, result, error, max_error_len,
  164.                             CONFIG_TRAPPER_TIMEOUT);
  165.                     break;
  166. +               case ZBX_SCRIPT_EXECUTE_ON_PROXY:
  167. +                   ret = zbx_execute_script_on_proxy(host, script->command, result,
  168. +                           error, max_error_len);
  169. +                   break;
  170.                 default:
  171.                     zbx_snprintf(error, max_error_len, "Invalid 'Execute on' option [%d]",
  172.                             (int)script->execute_on);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement