~kampka/ubuntu/quantal/zabbix/upstart-support

« back to all changes in this revision

Viewing changes to frontends/php/include/items.inc.php

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2009-06-28 19:11:29 UTC
  • mfrom: (19.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090628191129-5esmmf2h3tbff1fv
* New upstream release
* Merge upstream config file to template (Closes: #528426)
* Move logrotate from Depends to Suggests (Closes: #534096)
* Server should not crash anymore if postgresql transaction fails
  (Closes: #520197)
* Update fr.po (Closes: #527559)
* Update es.po (Closes: #527600)
* Update sv.po (Closes: #528571)
* Update it.po (Closes: #529157)
* Update cs.po (Closes: #529502)
* Update de.po (Closes: #532344)

Show diffs side-by-side

added added

removed removed

Lines of Context:
201
201
                                'history'               => 7,
202
202
                                'status'                => ITEM_STATUS_ACTIVE,
203
203
                                'type'                  => ITEM_TYPE_ZABBIX,
204
 
                                'snmp_community'=> '',
 
204
                                'snmp_community'        => '',
205
205
                                'snmp_oid'              => '',
206
 
                                'value_type'    => ITEM_VALUE_TYPE_STR,
207
 
                                'trapper_hosts' => 'localhost',
 
206
                                'value_type'            => ITEM_VALUE_TYPE_STR,
 
207
                                'trapper_hosts'         => 'localhost',
208
208
                                'snmp_port'             => 161,
209
209
                                'units'                 => '',
210
 
                                'multiplier'    => 0,
 
210
                                'multiplier'            => 0,
211
211
                                'delta'                 => 0,
212
212
                                'snmpv3_securityname'   => '',
213
213
                                'snmpv3_securitylevel'  => 0,
214
214
                                'snmpv3_authpassphrase' => '',
215
215
                                'snmpv3_privpassphrase' => '',
216
 
                                'formula'                       => 0,
217
 
                                'trends'                        => 365,
 
216
                                'formula'               => 0,
 
217
                                'trends'                => 365,
218
218
                                'logtimefmt'            => '',
219
219
                                'valuemapid'            => 0,
220
220
                                'delay_flex'            => '',
221
 
                                'params'                        => '',
 
221
                                'params'                => '',
222
222
                                'ipmi_sensor'           => '',
223
223
                                'applications'          => array(),
224
224
                                'templateid'            => 0);
351
351
                        $item['hostid'] = $db_host['hostid'];
352
352
                        $item['applications'] = get_same_applications_for_host($item['applications'], $db_host['hostid']);
353
353
                        $item['templateid'] = $itemid;
354
 
                        
 
354
 
355
355
                        $result = add_item($item);
356
356
                        if(!$result) break;
357
357
                }
358
 
                
 
358
 
359
359
                if($result)
360
360
                        return $itemid;
361
361
 
362
362
                if($item['templateid'] == 0){
363
363
                        delete_item($itemid);
364
364
                }
365
 
                
 
365
 
366
366
        return $result;
367
367
        }
368
368
 
369
369
        function update_trigger_value_to_unknown_by_itemid($itemids){
370
370
                zbx_value2array($itemids);
371
 
                
 
371
 
372
372
                $now = time();
373
373
                $result = DBselect('SELECT DISTINCT t.triggerid '.
374
374
                                ' FROM triggers t,functions f '.
381
381
                                continue;
382
382
                        $triggerids[$row['triggerid']] = $row['triggerid'];
383
383
                }
384
 
                
 
384
 
385
385
                if(!empty($triggers)){
386
386
                        DBexecute('UPDATE triggers SET value='.TRIGGER_VALUE_UNKNOWN.' WHERE '.DBcondition('triggerid',$triggerids));
387
387
                }
392
392
        function update_item_status($itemids, $status){
393
393
                zbx_value2array($itemids);
394
394
                $result = true;
395
 
                
 
395
 
396
396
                $db_items = DBselect('SELECT itemid, status FROM items WHERE '.DBcondition('itemid',$itemids));
397
397
                while($row = DBfetch($db_items)){
398
398
                        $old_status=$row['status'];
403
403
                }
404
404
                if(!empty($itemids)){
405
405
                        update_trigger_value_to_unknown_by_itemid($itemids);
406
 
                        
 
406
 
407
407
                        if($status==ITEM_STATUS_ACTIVE)
408
408
                                $sql='UPDATE items SET status='.$status.",error='',nextcheck=0 ".
409
409
                                        ' WHERE '.DBcondition('itemid',$itemids);
410
410
                        else
411
411
                                $sql='UPDATE items SET status='.$status.
412
412
                                        ' WHERE '.DBcondition('itemid',$itemids);
413
 
                                        
 
413
 
414
414
                        $result = DBexecute($sql);
415
415
                }
416
416
 
430
430
                'formula','trends','logtimefmt','valuemapid','delay_flex','params','ipmi_sensor','applications','templateid');
431
431
//*/
432
432
                $item_in_params = $item;
433
 
                
 
433
 
434
434
                $item_data = get_item_by_itemid_limited($itemid);
435
435
                $item_data['applications'] = get_applications_by_itemid($itemid);
436
436
                
438
438
                        error('Incorrect arguments pasted to function [update_item]');
439
439
                        return false;
440
440
                }
441
 
                
 
441
 
442
442
                $host = get_host_by_hostid($item['hostid']);
443
443
 
444
444
                if(($i = array_search(0,$item['applications'])) !== FALSE)
485
485
                $db_tmp_items = DBselect('SELECT itemid, hostid FROM items WHERE templateid='.$itemid);
486
486
                while($db_tmp_item = DBfetch($db_tmp_items)){
487
487
                        $child_item_params = $item_in_params;
488
 
                        
 
488
 
489
489
                        $child_item_params['hostid'] = $db_tmp_item['hostid'];
490
490
                        $child_item_params['templateid'] = $itemid;
491
491
                        $child_item_params['applications'] = get_same_applications_for_host($item['applications'], $db_tmp_item['hostid']);
494
494
                                error('Incorrect arguments pasted to function [update_item]');
495
495
                                return false;
496
496
                        }
497
 
                        
 
497
 
498
498
                        $result = update_item($db_tmp_item['itemid'], $child_item_params);              // recursion!!!
499
499
 
500
500
                        if(!$result)
557
557
                if($result){
558
558
                        info("Item '".$host['host'].':'.$item['key_']."' updated");
559
559
                }
560
 
                
 
560
 
561
561
        return $result;
562
562
        }
563
563
 
573
573
         * Comments:
574
574
         *
575
575
         */
576
 
        function smart_update_item($itemid, $item=array()){             
 
576
        function smart_update_item($itemid, $item=array()){
577
577
                $item_data = get_item_by_itemid_limited($itemid);
578
578
                
579
579
                $restore_rules= array(
580
 
                                        'description'   => array(),
 
580
                                        'description'           => array(),
581
581
                                        'key_'                  => array(),
582
582
                                        'hostid'                => array(),
583
583
                                        'delay'                 => array('template' => 1),
584
584
                                        'history'               => array('template' => 1 , 'httptest' => 1),
585
585
                                        'status'                => array('template' => 1 , 'httptest' => 1),
586
586
                                        'type'                  => array(),
587
 
                                        'snmp_community'=> array(),
 
587
                                        'snmp_community'        => array(),
588
588
                                        'snmp_oid'              => array(),
589
 
                                        'value_type'    => array(),
590
 
                                        'trapper_hosts' => array(),
 
589
                                        'value_type'            => array(),
 
590
                                        'trapper_hosts'         => array(),
591
591
                                        'snmp_port'             => array(),
592
592
                                        'units'                 => array(),
593
 
                                        'multiplier'    => array(),
 
593
                                        'multiplier'            => array(),
594
594
                                        'delta'                 => array('template' => 1 , 'httptest' => 1),
595
595
                                        'snmpv3_securityname'   => array(),
596
596
                                        'snmpv3_securitylevel'  => array(),
598
598
                                        'snmpv3_privpassphrase' => array(),
599
599
                                        'formula'               => array(),
600
600
                                        'trends'                => array('template' => 1 , 'httptest' => 1),
601
 
                                        'logtimefmt'    => array(),
602
 
                                        'valuemapid'    => array('httptest' => 1),
 
601
                                        'logtimefmt'            => array(),
 
602
                                        'valuemapid'            => array('httptest' => 1),
603
603
                                        'params'                => array(),
604
 
                                        'delay_flex'    => array(),
605
 
                                        'ipmi_sensor'   => array());
 
604
                                        'delay_flex'            => array('template' => 1),
 
605
                                        'ipmi_sensor'           => array());
606
606
 
607
607
                foreach($restore_rules as $var_name => $info){
608
608
                        if(($item_data['type'] == ITEM_TYPE_HTTPTEST) && !isset($info['httptest'])){
609
609
                                $item[$var_name] = $item_data[$var_name];
610
610
                        }
611
 
                                
 
611
 
612
612
                        if(!isset($info['template']) && (0 != $item_data['templateid'])){
613
613
                                $item[$var_name] = $item_data[$var_name];
614
614
                        }
615
 
                                
 
615
 
616
616
                        if(!array_key_exists($var_name,$item)){
617
617
                                $item[$var_name] = $item_data[$var_name];
618
618
                        }
638
638
         */
639
639
        function delete_template_items($hostid, $templateids = null, $unlink_mode = false){
640
640
                zbx_value2array($templateids);
641
 
                
 
641
 
642
642
                $db_items = get_items_by_hostid($hostid);
643
643
                while($db_item = DBfetch($db_items)){
644
644
                        if($db_item["templateid"] == 0)
679
679
                $db_tmp_item['hostid'] = $hostid;
680
680
                $db_tmp_item['applications'] = get_same_applications_for_host(get_applications_by_itemid($db_tmp_item['itemid']),$hostid);
681
681
                $db_tmp_item['templateid'] = $copy_mode?0:$db_tmp_item['itemid'];
682
 
                
 
682
 
683
683
                $result = add_item($db_tmp_item);
684
 
                        
 
684
 
685
685
        return $result;
686
686
        }
687
687
 
701
701
                if($templateid == null){
702
702
                        $templateid = array_keys(get_templates_by_hostid($hostid));
703
703
                }
704
 
                
 
704
 
705
705
                if(is_array($templateid)){
706
706
                        foreach($templateid as $id)
707
707
                                copy_template_items($hostid, $id, $copy_mode); // attention recursion
811
811
 *              Aly 
812
812
 *
813
813
 * Comments: 
814
 
 *              $error= true : rise Error if item doesn't exists(error generated), false: special processing (NO error generated)
 
814
 *              $error= true : rise Error if item doesn't exist (error generated), false: special processing (NO error generated)
815
815
 */
816
816
        function get_same_item_for_host($item,$dest_hostid, $error=true){
817
 
        
 
817
 
818
818
                if(!is_array($item)){
819
819
                        $itemid = $item;
820
820
                }
821
821
                else if(isset($item['itemid'])){
822
822
                        $itemid = $item['itemid'];
823
823
                }
824
 
                
 
824
 
825
825
                if(isset($itemid)){
826
826
                        $sql = 'SELECT src.itemid '.
827
827
                                                        ' FROM items src, items dest '.
828
828
                                                        ' WHERE dest.itemid='.$itemid.
829
829
                                                                ' AND src.key_=dest.key_ '.
830
830
                                                                ' AND src.hostid='.$dest_hostid;
831
 
                                                                
 
831
 
832
832
                        $db_item = DBfetch(DBselect($sql));
833
833
                        if (!$db_item && $error){
834
834
                                $item = get_item_by_itemid($db_item['itemid']);
835
835
                                $host = get_host_by_hostid($dest_hostid);
836
 
                                error('Missed key "'.$item['key_'].'" for host "'.$host['host'].'"');
 
836
                                error('Missing key "'.$item['key_'].'" for host "'.$host['host'].'"');
837
837
                        }
838
838
                        else{
839
839
                                if(is_array($item)){
844
844
                                }
845
845
                        }
846
846
                }
847
 
        return false;   
 
847
        return false;
848
848
        }
849
849
 
850
850
        /******************************************************************************
896
896
                if(!$result)    return  $result;
897
897
 
898
898
                $temp_arr = array(SCREEN_RESOURCE_SIMPLE_GRAPH,SCREEN_RESOURCE_PLAIN_TEXT);
899
 
                
 
899
 
900
900
                DBexecute('DELETE FROM screens_items WHERE '.DBcondition('resourceid',$itemids).' AND '.DBcondition('resourcetype', $temp_arr));
901
901
                DBexecute('DELETE FROM items_applications WHERE '.DBcondition('itemid',$itemids));
902
902
                DBexecute("DELETE FROM profiles WHERE idx='web.favorite.graphids' AND source='itemid' AND ".DBcondition('value_id',$itemids));
903
 
                
 
903
 
904
904
                $result = DBexecute('DELETE FROM items WHERE '.DBcondition('itemid',$itemids));
905
905
                if($result){
906
906
                        foreach($items as $itemid => $item){
989
989
 * Function: get_items_data_overview
990
990
 *
991
991
 * Description:
992
 
 *     Retrive overview table object for items
 
992
 *     Retrieve overview table object for items
993
993
 *
994
994
 * Author:
995
995
 *     Eugene Grigorjev (eugene.grigorjev@zabbix.com)
1049
1049
                                );
1050
1050
                        }
1051
1051
                }
1052
 
                
 
1052
 
1053
1053
                if(!isset($hosts)){
1054
1054
                        return $table;
1055
1055
                }
1063
1063
                        foreach($hosts as $hostname){
1064
1064
                                $header=array_merge($header,array(new CImg('vtext.php?text='.$hostname)));
1065
1065
                        }
1066
 
                        
 
1066
 
1067
1067
                        $table->SetHeader($header,'vertical_header');
1068
1068
                        $curr_rime = time();
1069
 
                        
 
1069
 
1070
1070
                        foreach($items as $descr => $ithosts){
1071
1071
                                $table_row = array(nbsp($descr));
1072
1072
                                foreach($hosts as $hostname){
1080
1080
                        foreach($items as $descr => $ithosts){
1081
1081
                                $header=array_merge($header,array(new CImg('vtext.php?text='.$descr)));
1082
1082
                        }
1083
 
                        
 
1083
 
1084
1084
                        $table->SetHeader($header,'vertical_header');
1085
1085
                        $curr_rime = time();
1086
1086
                        
1112
1112
                                else
1113
1113
                                        $ack = null;
1114
1114
                        }
1115
 
                        
 
1115
 
1116
1116
                        $value = format_lastvalue($ithosts[$hostname]);
1117
1117
 
1118
1118
                        $it_ov_menu = array(
1215
1215
                                $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
1216
1216
                                                        " VALUES ($housekeeperid,'history_text','itemid',$itemid)";
1217
1217
                                DBexecute($sql);
1218
 
                                
 
1218
 
1219
1219
                                $housekeeperid = get_dbid('housekeeper','housekeeperid');
1220
1220
                                $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
1221
1221
                                                        " VALUES ($housekeeperid,'history_log','itemid',$itemid)";
1222
1222
                                DBexecute($sql);
1223
 
                                                        
 
1223
 
1224
1224
                                $housekeeperid = get_dbid('housekeeper','housekeeperid');
1225
1225
                                $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
1226
1226
                                                        " VALUES ($housekeeperid,'history_uint','itemid',$itemid)";
1227
1227
                                DBexecute($sql);
1228
 
                                                        
 
1228
 
1229
1229
                                $housekeeperid = get_dbid('housekeeper','housekeeperid');
1230
1230
                                $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
1231
1231
                                                        " VALUES ($housekeeperid,'history_str','itemid',$itemid)";
1232
1232
                                DBexecute($sql);
1233
 
                                                        
 
1233
 
1234
1234
                                $housekeeperid = get_dbid('housekeeper','housekeeperid');
1235
1235
                                $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
1236
1236
                                                        " VALUES ($housekeeperid,'history','itemid',$itemid)";
1267
1267
        }
1268
1268
        
1269
1269
        function format_lastvalue($db_item){
1270
 
                if($db_item["value_type"] == ITEM_VALUE_TYPE_LOG){
1271
 
                        $row=DBfetch(DBselect('SELECT value FROM history_log WHERE itemid='.$db_item['itemid'].' ORDER BY clock DESC', 1));
1272
 
                        if($row){
1273
 
                                $lastvalue=/*nbsp(htmlspecialchars(*/$row['value']/*))*/;
 
1270
                if(isset($db_item["lastvalue"])){
 
1271
                        if($db_item["value_type"] == ITEM_VALUE_TYPE_FLOAT){
 
1272
                                $lastvalue=convert_units($db_item["lastvalue"],$db_item["units"]);
 
1273
                        }
 
1274
                        else if($db_item["value_type"] == ITEM_VALUE_TYPE_UINT64){
 
1275
                                $lastvalue=convert_units($db_item["lastvalue"],$db_item["units"]);
 
1276
                        }
 
1277
                        else if($db_item["value_type"] == ITEM_VALUE_TYPE_STR ||
 
1278
                                        $db_item["value_type"] == ITEM_VALUE_TYPE_TEXT ||
 
1279
                                        $db_item["value_type"] == ITEM_VALUE_TYPE_LOG){
 
1280
                                $lastvalue=$db_item["lastvalue"];
1274
1281
                                if(strlen($lastvalue) > 20)
1275
1282
                                        $lastvalue = substr($lastvalue,0,20)." ...";
1276
1283
                                $lastvalue = nbsp(htmlspecialchars($lastvalue));
1277
1284
                        }
1278
1285
                        else{
1279
 
                                $lastvalue='-';
1280
 
                        }
1281
 
 
1282
 
                }
1283
 
                else if(isset($db_item["lastvalue"])){
1284
 
                        if($db_item["value_type"] == ITEM_VALUE_TYPE_FLOAT){
1285
 
                                $lastvalue=convert_units($db_item["lastvalue"],$db_item["units"]);
1286
 
                        }
1287
 
                        else if($db_item["value_type"] == ITEM_VALUE_TYPE_UINT64){
1288
 
                                $lastvalue=convert_units($db_item["lastvalue"],$db_item["units"]);
1289
 
                        }
1290
 
                        else if($db_item["value_type"] == ITEM_VALUE_TYPE_TEXT){
1291
 
                                $lastvalue="...";
1292
 
                        }
1293
 
                        else if($db_item["value_type"] == ITEM_VALUE_TYPE_STR){
1294
 
                                        $lastvalue=nbsp(htmlspecialchars(substr($db_item["lastvalue"],0,20)));
1295
 
                                        if(strlen($db_item["lastvalue"]) > 20)
1296
 
                                                $lastvalue .= " ...";
1297
 
                        }
1298
 
                        else{
1299
1286
                                $lastvalue="Unknown value type";
1300
1287
                        }
1301
1288
                        if($db_item["valuemapid"] > 0);
1314
1301
         * Description:
1315
1302
         *     Get value from history
1316
1303
         *
1317
 
         * Peremeters:
 
1304
         * Paremeters:
1318
1305
         *     itemid - item ID
1319
1306
         *     last  - 0 - last value (clock is used), 1 - last value
1320
1307
         *
1373
1360
         * Purpose: check if current time is within given period
1374
1361
         *
1375
1362
         * Parameters: period - time period in format [d1-d2,hh:mm-hh:mm]*
1376
 
         *             now    - timestamp for comporation
 
1363
         *             now    - timestamp for comparison
1377
1364
         *
1378
1365
         * Return value: 0 - out of period, 1 - within the period
1379
1366
         *
1386
1373
        function        check_time_period($period, $now)
1387
1374
        {
1388
1375
                $tm = localtime($now, TRUE);
1389
 
 
1390
 
                $day = $tm['tm_wday'];
1391
 
                if (0 == $day)
1392
 
                        $day = 7;
1393
 
                $min = 60 * $tm['tm_hour'] + $tm['tm_min'];
 
1376
                $day = (0 == $tm['tm_wday']) ? 7 : $tm['tm_wday'];
 
1377
                $sec = 3600 * $tm['tm_hour'] + 60 * $tm['tm_min'] + $tm['tm_sec'];
1394
1378
 
1395
1379
                $arr_of_period = explode(';', $period);
1396
1380
 
1397
1381
                foreach($arr_of_period as $one_period)
1398
1382
                {
1399
1383
                        list($d1, $d2, $h1, $m1, $h2, $m2) = sscanf($one_period, "%d-%d,%d:%d-%d:%d");
1400
 
                        if ($day >= $d1 && $day <= $d2 && $min >= 60 * $h1 + $m1 && $min <= 60 * $h2 + $m2)
 
1384
                        if ($day >= $d1 && $day <= $d2 && $sec >= 3600 * $h1 + 60 * $m1 && $sec <= 3600 * $h2 + 60 * $m2)
1401
1385
                        {
1402
1386
                                return 1;
1403
1387
                        }
1407
1391
        }
1408
1392
 
1409
1393
        /*
 
1394
         *
 
1395
         * Function: get_flexible_interval
 
1396
         *
 
1397
         * Purpose: check for flexible delay value
 
1398
         *
 
1399
         * Parameters: delay_flex - [IN] separated flexible intervals
 
1400
         *                          [dd/d1-d2,hh:mm-hh:mm;]
 
1401
         *             delay - [IN] default delay
 
1402
         *
 
1403
         * Return value: flexible delay or $delay if $delay_flex is not defined
 
1404
         *
 
1405
         *
 
1406
         * Author: Alexander Vladishev
 
1407
         *
 
1408
         */
 
1409
        function        get_flexible_interval($delay_flex, $delay, $now)
 
1410
        {
 
1411
                if (is_null($delay_flex) || $delay_flex == '')
 
1412
                        return $delay;
 
1413
 
 
1414
                $arr_of_delay = explode(';', $delay_flex);
 
1415
 
 
1416
                foreach($arr_of_delay as $one_delay_flex)
 
1417
                {
 
1418
                        $arr = explode('/', $one_delay_flex);
 
1419
                        if (check_time_period($arr[1], $now))
 
1420
                        {
 
1421
                                return $arr[0];
 
1422
                        }
 
1423
                }
 
1424
 
 
1425
                return $delay;
 
1426
        }
 
1427
 
 
1428
        /*
 
1429
         *
 
1430
         * Function: get_next_flexible_interval
 
1431
         *
 
1432
         * Purpose: return time of next flexible interval
 
1433
         *
 
1434
         * Parameters: delay_flex - [IN] ';' separated flexible intervals
 
1435
         *                          [dd/d1-d2,hh:mm-hh:mm]
 
1436
         *             now = [IN] current time
 
1437
         *
 
1438
         * Return value: start of next interval
 
1439
         *
 
1440
         * Author: Alexei Vladishev, Alexander Vladishev
 
1441
         *
 
1442
         */
 
1443
        function        get_next_flexible_interval($delay_flex, $now)
 
1444
        {
 
1445
                if (is_null($delay_flex) || $delay_flex == '')
 
1446
                        return -1;
 
1447
 
 
1448
                $tm = localtime($now, TRUE);
 
1449
                $day = (0 == $tm['tm_wday']) ? 7 : $tm['tm_wday'];
 
1450
                $sec = 3600 * $tm['tm_hour'] + 60 * $tm['tm_min'] + $tm['tm_sec'];
 
1451
                $next = 0;
 
1452
 
 
1453
                $arr_of_delay_flex = explode(';', $delay_flex);
 
1454
 
 
1455
                foreach($arr_of_delay_flex as $one_delay_flex)
 
1456
                {
 
1457
                        if (7 == sscanf($one_delay_flex, "%d/%d-%d,%d:%d-%d:%d", $delay, $d1, $d2, $h1, $m1, $h2, $m2))
 
1458
                        {
 
1459
                                $sec1 = 3600 * $h1 + 60 * $m1;
 
1460
                                $sec2 = 3600 * $h2 + 60 * $m2;
 
1461
 
 
1462
                                if ($day >= $d1 && $day <= $d2 && $sec >= $sec1 && $sec <= $sec2)       /* working period */
 
1463
                                {
 
1464
                                        if ($next == 0 || $next > $now - $sec + $sec2)
 
1465
                                                $next = $now - $sec + $sec2;
 
1466
                                        break;
 
1467
                                }
 
1468
 
 
1469
                                if ($day >= $d1 && $day <= $d2 && $sec < $sec1)                         /* next period, same day */
 
1470
                                {
 
1471
                                        if ($next == 0 || $next > $now - $sec + $sec1)
 
1472
                                                $next = $now - $sec + $sec1;
 
1473
                                }
 
1474
                                else if ($day + 1 >= $d1 && $day + 1 <= $d2 && $sec < $sec1)            /* next period, next  day */
 
1475
                                {
 
1476
                                        if ($next == 0 || $next > $now - $sec + $sec1)
 
1477
                                                $next = $now - $sec + 86400 + $sec1;
 
1478
                                }
 
1479
                        }
 
1480
                }
 
1481
 
 
1482
                return $next ? $next : -1;
 
1483
        }
 
1484
 
 
1485
        /*
1410
1486
         * Function: calculate_item_nextcheck
1411
1487
         *
1412
1488
         * Description:
1413
 
         *     calculate nextcheck timespamp for item
 
1489
         *     calculate nextcheck timestamp for item
1414
1490
         *
1415
 
         * Peremeters:
 
1491
         * Parameters:
1416
1492
         *     itemid - item ID
1417
1493
         *     item_type - item type
1418
1494
         *     delay - item's refresh rate in sec
1437
1513
                /* Special processing of active items to see better view in queue */
1438
1514
                if ($item_type == ITEM_TYPE_ZABBIX_ACTIVE)
1439
1515
                {
1440
 
                        return $now + $delay;
 
1516
                        return array('nextcheck' => $now + $delay, 'delay' => $delay);
1441
1517
                }
1442
1518
 
1443
 
                if (!is_null($delay_flex) && $delay_flex != '')
 
1519
                $flex_delay = get_flexible_interval($delay_flex, $delay, $now);
 
1520
 
 
1521
                if (-1 != ($next = get_next_flexible_interval($delay_flex, $now)) && (($now + $flex_delay) > $next))
1444
1522
                {
1445
 
                        $arr_of_delay = explode(';', $delay_flex);
 
1523
                        $flex_delay2 = get_flexible_interval($delay_flex, $delay, $next + 1);
1446
1524
 
1447
 
                        foreach($arr_of_delay as $one_delay_flex)
1448
 
                        {
1449
 
                                $arr = explode('/', $one_delay_flex);
1450
 
                                if (check_time_period($arr[1], $now))
1451
 
                                {
1452
 
                                        $delay = $arr[0];
1453
 
                                        break;
1454
 
                                }
1455
 
                        }
 
1525
                        $now = $next;
 
1526
                        $flex_delay = min($flex_delay, $flex_delay2);
1456
1527
                }
1457
1528
 
1458
 
                if (0 == $delay)
 
1529
                if (0 == $flex_delay)
1459
1530
                {
1460
1531
/*                      info('Invalid item update interval ['.$delay.'], using default [30]');*/
1461
 
                        $delay = 30;
 
1532
                        $flex_delay = 30;
1462
1533
                }
1463
1534
 
 
1535
                $delay = $flex_delay;
1464
1536
                $nextcheck = $delay * floor($now / $delay) + ($itemid % $delay);
1465
1537
 
1466
1538
                while ($nextcheck <= $now)
1468
1540
                        $nextcheck += $delay;
1469
1541
                }
1470
1542
 
1471
 
                return $nextcheck;
 
1543
                return array('nextcheck' => $nextcheck, 'delay' => $delay);
1472
1544
        }
1473
1545
?>