Advertisement
tylkas

ZBXNEXT-473

Feb 8th, 2013
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 13.14 KB | None | 0 0
  1. Index: include/common.h
  2. ===================================================================
  3. --- include/common.h    (revision 33506)
  4. +++ include/common.h    (working copy)
  5. @@ -475,6 +475,7 @@
  6.     ITEM_STATUS_NOTSUPPORTED = 3,
  7.  /*ITEM_STATUS_DELETED      4*/
  8.  /*ITEM_STATUS_NOTAVAILABLE 5*/
  9. +   ITEM_STATUS_CHECKNOW = 6
  10.  } zbx_item_status_t;
  11.  
  12.  /* trigger types */
  13. Index: src/libs/zbxdbcache/dbconfig.c
  14. ===================================================================
  15. --- src/libs/zbxdbcache/dbconfig.c  (revision 33506)
  16. +++ src/libs/zbxdbcache/dbconfig.c  (working copy)
  17. @@ -864,6 +864,20 @@
  18.             }
  19.         }
  20.  
  21. +       if (ITEM_STATUS_CHECKNOW == status)
  22. +       {
  23. +           /* set nextcheck for item with delay "1" */
  24. +           zabbix_log(LOG_LEVEL_DEBUG, "Found CHECK_NOW status for item %d",itemid);
  25. +           item->nextcheck = calculate_item_nextcheck(item->interfaceid, itemid,
  26. +                   item->type, 1, row[16], now, NULL);
  27. +
  28. +           /* update status for item in database */
  29. +           DBexecute("update items set status=%d where itemid=%d", ITEM_STATUS_ACTIVE, itemid);
  30. +
  31. +           /* set item status in ACTIVE for dbcache */
  32. +           status = ITEM_STATUS_ACTIVE;
  33. +       }
  34. +
  35.         item->status = status;
  36.         item->delay = delay;
  37.  
  38. @@ -2308,10 +2322,10 @@
  39.             " from items i,hosts h"
  40.             " where i.hostid=h.hostid"
  41.                 " and h.status in (%d)"
  42. -               " and i.status in (%d,%d)"
  43. +               " and i.status in (%d,%d,%d)"
  44.                 ZBX_SQL_NODE,
  45.             HOST_STATUS_MONITORED,
  46. -           ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED,
  47. +           ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_STATUS_CHECKNOW,
  48.             DBand_node_local("i.itemid"));
  49.     isec = zbx_time() - sec;
  50.  
  51. Index: frontends/php/latest.php
  52. ===================================================================
  53. --- frontends/php/latest.php    (revision 33506)
  54. +++ frontends/php/latest.php    (working copy)
  55. @@ -50,6 +50,8 @@
  56.     'hostid'=>              array(T_ZBX_INT, O_OPT, P_SYS,  DB_ID,      NULL),
  57.  
  58.     'fullscreen'=>          array(T_ZBX_INT, O_OPT, P_SYS,  IN('0,1'),  NULL),
  59. +// actions
  60. +   'checkbutton'=>             array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,  null),
  61.  // filter
  62.     'select'=>              array(T_ZBX_STR, O_OPT, NULL,   NULL,       NULL),
  63.     'show_without_data'=>   array(T_ZBX_INT, O_OPT, NULL,   IN('0,1'),  NULL),
  64. @@ -76,6 +78,22 @@
  65.  }
  66.  //--------
  67.  
  68. +/* Actions */
  69. +if (isset($_REQUEST['checkbutton'])) {
  70. +   $group_itemid = $_REQUEST['checkbutton'];
  71. +
  72. +   DBstart();
  73. +   $go_result = checknow_item($group_itemid);
  74. +   DBend($go_result);
  75. +
  76. +   $new_get = $_GET;
  77. +   unset($new_get['checkbutton']);
  78. +   $new_get_string = http_build_query($new_get);
  79. +
  80. +   print "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=latest.php?".$new_get_string."'>";
  81. +}
  82. +//--------
  83. +
  84.  /* FILTER */
  85.  if (!isset($_REQUEST['show_without_data'])) {
  86.     $_REQUEST['show_without_data'] = 0;
  87. @@ -193,6 +211,8 @@
  88.     make_sorting_header(_('Last check'), 'i.lastclock'),
  89.     _('Last value'),
  90.     _x('Change', 'noun in latest data'),
  91. +   _('Current status'),
  92. +   _('Force check'),
  93.     _('History')
  94.  ));
  95.  
  96. @@ -260,7 +280,7 @@
  97.         ' WHERE '.dbConditionInt('ia.applicationid',$db_appids).
  98.             ' AND i.itemid=ia.itemid'.
  99.             ($_REQUEST['show_without_data'] ? '' : ' AND i.lastvalue IS NOT NULL').
  100. -           ' AND (i.status='.ITEM_STATUS_ACTIVE.' OR i.status='.ITEM_STATUS_NOTSUPPORTED.')'.
  101. +           ' AND i.status in ('.ITEM_STATUS_ACTIVE.', '.ITEM_STATUS_NOTSUPPORTED.', '.ITEM_STATUS_CHECKNOW.')'.
  102.             ' AND '.dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)).
  103.         order_by('i.name,i.itemid,i.lastclock');
  104.  
  105. @@ -316,6 +336,21 @@
  106.         $change = ' - ';
  107.     }
  108.  
  109. +   /* create "checknow" button for this item */
  110. +   $checknow = '';
  111. +   if ( !in_array($db_item['type'], itemsblacklist2array()) ) {
  112. +       $dbHostStatuses = DBselect('SELECT h.status'.
  113. +                   ' FROM hosts h,items i'.
  114. +                   ' WHERE h.hostid='.$db_item['hostid']);
  115. +       $dbHostStatus = DBfetch($dbHostStatuses);
  116. +       if (($dbHostStatus['status']==0) && ($db_item['delay'] > ITEM_CHECKNOW_MINDELAY)) {
  117. +           $checknow = new CButton("checkbutton", _('Force check'), 'javascript:'.
  118. +                       ' if (confirm("This may cause a false trigger alarm. Are you sure?")){'.
  119. +                       ' var uri = new Curl(location.href); uri.setArgument("checkbutton",'.
  120. +                       $db_item['itemid'].'); location.href = uri.getUrl();}');
  121. +       }
  122. +   }
  123. +
  124.     if(($db_item['value_type']==ITEM_VALUE_TYPE_FLOAT) || ($db_item['value_type']==ITEM_VALUE_TYPE_UINT64)){
  125.         $actions = new CLink(_('Graph'),'history.php?action=showgraph&itemid='.$db_item['itemid']);
  126.     }
  127. @@ -333,6 +368,8 @@
  128.         new CCol($lastclock, $item_status),
  129.         new CCol($lastvalue, $item_status),
  130.         new CCol($change, $item_status),
  131. +       item_status2str($db_item['status']),
  132. +       $checknow,
  133.         $actions
  134.     )));
  135.  }
  136. @@ -378,7 +415,7 @@
  137.  
  138.     $col = new CCol(array(bold($db_app['name']),SPACE.'('._n('%1$s Item', '%1$s Items', $db_app['item_cnt']).')'));
  139.  
  140. -   $col->setColSpan(5);
  141. +   $col->setColSpan(7);
  142.     // host JS menu link
  143.  
  144.     $hostSpan = null;
  145. @@ -554,7 +591,7 @@
  146.  
  147.  
  148.     $col = new CCol(array(bold('- '.('other').' -'), SPACE.'('._n('%1$s Item', '%1$s Items', $db_host['item_cnt']).')'));
  149. -   $col->setColSpan(5);
  150. +   $col->setColSpan(7);
  151.  
  152.     // host JS menu link
  153.     $hostSpan = null;
  154. Index: frontends/php/include/defines.inc.php
  155. ===================================================================
  156. --- frontends/php/include/defines.inc.php   (revision 33506)
  157. +++ frontends/php/include/defines.inc.php   (working copy)
  158. @@ -330,7 +330,13 @@
  159.  define('ITEM_TYPE_TELNET',         14);
  160.  define('ITEM_TYPE_CALCULATED',     15);
  161.  define('ITEM_TYPE_JMX',                16);
  162. +define('ITEM_TYPE_SNMPTRAP',       17);
  163.  
  164. +define('ITEM_CHECKNOW_BLACKLIST', ITEM_TYPE_TRAPPER.', '.
  165. +               ITEM_TYPE_ZABBIX_ACTIVE.', '.
  166. +               ITEM_TYPE_SNMPTRAP);
  167. +define('ITEM_CHECKNOW_MINDELAY',   59);
  168. +
  169.  define('ITEM_VALUE_TYPE_FLOAT',        0);
  170.  define('ITEM_VALUE_TYPE_STR',      1);
  171.  define('ITEM_VALUE_TYPE_LOG',      2);
  172. @@ -356,9 +362,8 @@
  173.  define('ITEM_STATUS_ACTIVE',       0);
  174.  define('ITEM_STATUS_DISABLED',     1);
  175.  define('ITEM_STATUS_NOTSUPPORTED', 3);
  176. +define('ITEM_STATUS_CHECKNOW',     6);
  177.  
  178. -define('ITEM_TYPE_SNMPTRAP', 17);
  179. -
  180.  define('ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV',   0);
  181.  define('ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV',     1);
  182.  define('ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV',       2);
  183. Index: frontends/php/include/items.inc.php
  184. ===================================================================
  185. --- frontends/php/include/items.inc.php (revision 33506)
  186. +++ frontends/php/include/items.inc.php (working copy)
  187. @@ -148,7 +148,8 @@
  188.     $types = array(
  189.         ITEM_STATUS_ACTIVE => _('Enabled'),
  190.         ITEM_STATUS_DISABLED => _('Disabled'),
  191. -       ITEM_STATUS_NOTSUPPORTED => _('Not supported')
  192. +       ITEM_STATUS_NOTSUPPORTED => _('Not supported'),
  193. +       ITEM_STATUS_CHECKNOW => _('Forced checking')
  194.     );
  195.     if (is_null($type)) {
  196.         return $types;
  197. @@ -165,6 +166,8 @@
  198.     switch ($status) {
  199.         case ITEM_STATUS_ACTIVE:
  200.             return 'off';
  201. +       case ITEM_STATUS_CHECKNOW:
  202. +           return 'off';
  203.         case ITEM_STATUS_DISABLED:
  204.             return 'on';
  205.         case ITEM_STATUS_NOTSUPPORTED:
  206. Index: frontends/php/include/views/configuration.item.list.php
  207. ===================================================================
  208. --- frontends/php/include/views/configuration.item.list.php (revision 33506)
  209. +++ frontends/php/include/views/configuration.item.list.php (working copy)
  210. @@ -61,7 +61,8 @@
  211.     make_sorting_header(_('Type'), 'type'),
  212.     _('Applications'),
  213.     make_sorting_header(_('Status'), 'status'),
  214. -   _('Error')
  215. +   _('Error'),
  216. +   _('Force check')
  217.  ));
  218.  
  219.  foreach ($this->data['items'] as $item) {
  220. @@ -93,6 +94,21 @@
  221.     }
  222.     $statusIcons = array($error);
  223.  
  224. +   /* create "checknow" button for this item */
  225. +   $checknow = '';
  226. +   if (!in_array($item['type'], itemsblacklist2array()) ) {
  227. +       $dbHostStatuses = DBselect('SELECT h.status'.
  228. +                   ' FROM hosts h,items i'.
  229. +                   ' WHERE h.hostid='.$item['hostid']);
  230. +       $dbHostStatus = DBfetch($dbHostStatuses);
  231. +       if (($dbHostStatus['status'] == 0) && ($item['delay'] > ITEM_CHECKNOW_MINDELAY)) {
  232. +           $checknow = new CButton("checkbutton", _('Force check'), 'javascript:'.
  233. +                   ' var uri = new Curl(location.href); uri.setArgument("go","checknow");'.
  234. +                   ' uri.setArgument("group_itemid",'.$item['itemid'].
  235. +                   '); location.href = uri.getUrl();');
  236. +       }
  237. +   }
  238. +
  239.     // discovered item lifetime indicator
  240.     if ($item['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $item['itemDiscovery']['ts_delete']) {
  241.         $deleteError = new CDiv(SPACE, 'status_icon iconwarning');
  242. @@ -228,7 +244,8 @@
  243.         item_type2str($item['type']),
  244.         new CCol($item['applications_list'], 'wraptext'),
  245.         $status,
  246. -       $statusIcons
  247. +       $statusIcons,
  248. +       $checknow
  249.     ));
  250.  }
  251.  
  252. @@ -242,6 +259,11 @@
  253.  $goOption->setAttribute('confirm', _('Disable selected items?'));
  254.  $goComboBox->addItem($goOption);
  255.  
  256. +$goOption = new CComboItem('checknow', _('Force check to selected'));
  257. +$goOption->setAttribute('confirm', _('Checking a large number of items at the same time
  258. +can degrade the performance of the server!'));
  259. +$goComboBox->addItem($goOption);
  260. +
  261.  $goOption = new CComboItem('massupdate', _('Mass update'));
  262.  $goComboBox->addItem($goOption);
  263.  
  264. Index: frontends/php/include/forms.inc.php
  265. ===================================================================
  266. --- frontends/php/include/forms.inc.php (revision 33506)
  267. +++ frontends/php/include/forms.inc.php (working copy)
  268. @@ -431,7 +431,7 @@
  269.         // status select
  270.         $cmbStatus = new CComboBox('filter_status', $filter_status);
  271.         $cmbStatus->addItem(-1, _('all'));
  272. -       foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED, ITEM_STATUS_NOTSUPPORTED) as $status) {
  273. +       foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED, ITEM_STATUS_NOTSUPPORTED, ITEM_STATUS_CHECKNOW) as $status) {
  274.             $cmbStatus->addItem($status, item_status2str($status));
  275.         }
  276.  
  277. Index: frontends/php/include/func.inc.php
  278. ===================================================================
  279. --- frontends/php/include/func.inc.php  (revision 33506)
  280. +++ frontends/php/include/func.inc.php  (working copy)
  281. @@ -661,6 +661,23 @@
  282.     return $value;
  283.  }
  284.  
  285. +/**
  286. + * Converts ITEM_CHECKNOW_BLACKLIST to array
  287. + *
  288. + * @return array of int
  289. + */
  290. +function itemsblacklist2array() {
  291. +   $tempblacklistarray = explode(", ", ITEM_CHECKNOW_BLACKLIST);
  292. +   $blacklistarray = array();
  293. +
  294. +   for ($i = 0; $i < count($tempblacklistarray); $i++) {
  295. +       if (isset($blacklistarray[$i])) {
  296. +           array_unshift($blacklistarray,  constant($tempblacklistarray[i]));
  297. +       }
  298. +   }
  299. +   return $blacklistarray;
  300. +}
  301. +
  302.  /************* ZBX MISC *************/
  303.  function zbx_avg($values) {
  304.     zbx_value2array($values);
  305. @@ -2459,3 +2476,25 @@
  306.  function checkRequiredKeys(array $array, array $keys) {
  307.     return array_diff($keys, array_keys($array));
  308.  }
  309. +
  310. +/**
  311. + * Make SQL query, then set status="Forced check" for $itemids
  312. + *
  313. + * @return bool
  314. + */
  315. +function checknow_item($itemids) {
  316. +   zbx_value2array($itemids);
  317. +
  318. +   /* first update status for child items */
  319. +   $child_items = array();
  320. +   $db_items = DBselect('SELECT i.itemid FROM items i,hosts h WHERE '.dbConditionInt('i.itemid', $itemids).
  321. +           ' AND i.type NOT IN ('.ITEM_CHECKNOW_BLACKLIST.')'.
  322. +           ' AND i.hostid=h.hostid'.
  323. +           ' AND i.delay>'.ITEM_CHECKNOW_MINDELAY.
  324. +           ' AND h.status=0');
  325. +
  326. +   while ($item = DBfetch($db_items)) {
  327. +       array_push($child_items, $item['itemid']);
  328. +   }
  329. +   return update_item_status($child_items, ITEM_STATUS_CHECKNOW);
  330. +}
  331. Index: frontends/php/items.php
  332. ===================================================================
  333. --- frontends/php/items.php (revision 33506)
  334. +++ frontends/php/items.php (working copy)
  335. @@ -150,6 +150,7 @@
  336.     'add_delay_flex' =>         array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,  null),
  337.     // actions
  338.     'go' =>                     array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,  null),
  339. +   'checknow' =>                   array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,  null),
  340.     'save' =>                   array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,  null),
  341.     'clone' =>                  array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,  null),
  342.     'update' =>                 array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,  null),
  343. @@ -180,7 +181,7 @@
  344.     'filter_delay' => array(T_ZBX_INT, O_OPT, P_UNSET_EMPTY, BETWEEN(0, SEC_PER_DAY), null, _('Update interval')),
  345.     'filter_history' => array(T_ZBX_INT, O_OPT, P_UNSET_EMPTY, BETWEEN(0, 65535), null, _('Keep history (in days)')),
  346.     'filter_trends' => array(T_ZBX_INT, O_OPT, P_UNSET_EMPTY, BETWEEN(0, 65535), null, _('Keep trends (in days)')),
  347. -   'filter_status' =>          array(T_ZBX_INT, O_OPT, null,   IN('-1,0,1,3'), null),
  348. +   'filter_status' =>          array(T_ZBX_INT, O_OPT, null,   IN('-1,0,1,3,6'), null),
  349.     'filter_templated_items' => array(T_ZBX_INT, O_OPT, null,   IN('-1,0,1'), null),
  350.     'filter_with_triggers' =>   array(T_ZBX_INT, O_OPT, null,   IN('-1,0,1'), null),
  351.     'filter_ipmi_sensor' =>     array(T_ZBX_STR, O_OPT, null,   null,       null),
  352. @@ -596,6 +597,15 @@
  353.     $go_result = DBend($go_result);
  354.     show_messages($go_result, _('Items disabled'), null);
  355.  }
  356. +elseif ($_REQUEST['go'] == 'checknow' && isset($_REQUEST['group_itemid'])) {
  357. +   global $USER_DETAILS;
  358. +   $group_itemid = $_REQUEST['group_itemid'];
  359. +
  360. +   DBstart();
  361. +   $go_result = checknow_item($group_itemid);
  362. +   $go_result = DBend($go_result);
  363. +   show_messages($go_result, _('Forced check for item activated'), null);
  364. +}
  365.  elseif ($_REQUEST['go'] == 'copy_to' && isset($_REQUEST['copy']) && isset($_REQUEST['group_itemid'])) {
  366.     if (isset($_REQUEST['copy_targetid']) && $_REQUEST['copy_targetid'] > 0 && isset($_REQUEST['copy_type'])) {
  367.         // host
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement