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

« back to all changes in this revision

Viewing changes to frontends/php/include/triggers.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:
630
630
                                $key            = &$arr[ZBX_EXPRESSION_SIMPLE_EXPRESSION_ID + ZBX_SIMPLE_EXPRESSION_KEY_ID];
631
631
                                $function       = &$arr[ZBX_EXPRESSION_SIMPLE_EXPRESSION_ID + ZBX_SIMPLE_EXPRESSION_FUNCTION_NAME_ID];
632
632
                                $parameter      = &$arr[ZBX_EXPRESSION_SIMPLE_EXPRESSION_ID + ZBX_SIMPLE_EXPRESSION_FUNCTION_PARAM_ID];
633
 
                                
 
633
 
634
634
                                /* Check host */
635
635
                                $sql = 'SELECT COUNT(*) as cnt,min(status) as status,min(hostid) as hostid '.
636
636
                                                ' FROM hosts h '.
693
693
                                                                continue;
694
694
                                                        }
695
695
                                                        else{
696
 
                                                                error('Missed mandatory parameter for function ('.$function.')');
 
696
                                                                error('Missing mandatory parameter for function ('.$function.')');
697
697
                                                                return false;
698
698
                                                        }
699
699
                                                }
711
711
                                        }
712
712
                                }
713
713
                        }
 
714
        
714
715
                        $expr = $arr[ZBX_EXPRESSION_LEFT_ID].$ZBX_TR_EXPR_REPLACE_TO.$arr[ZBX_EXPRESSION_RIGHT_ID];
715
716
                }
716
717
 
717
718
                if ( isset($h_status[HOST_STATUS_TEMPLATE]) && ( count($h_status) > 1 || count($h_status[HOST_STATUS_TEMPLATE]) > 1 )){
718
 
                        error("Incorrect trigger expression. You can't use template hosts".
719
 
                                " in mixed expressions.");
 
719
                        error('Incorrect trigger expression. You can not use template hosts in mixed expressions.');
720
720
                        return false;
721
721
                }
722
722
 
723
 
                /* Replace all calculations and numbers with '$ZBX_TR_EXPR_REPLACE_TO' */
 
723
/* Replace all calculations and numbers with '$ZBX_TR_EXPR_REPLACE_TO' */
724
724
                $expt_number = '('.$ZBX_TR_EXPR_REPLACE_TO.'|'.ZBX_EREG_NUMBER.')';
725
725
                $expt_term = '((\('.$expt_number.'\))|('.$expt_number.'))';
726
726
                $expr_format = '(('.$expt_term.ZBX_EREG_SPACES.ZBX_EREG_SIGN.ZBX_EREG_SPACES.$expt_term.')|(\('.$expt_term.'\)))';
730
730
                        $expr = substr($expr, 0, strpos($expr, $arr[1])).$ZBX_TR_EXPR_REPLACE_TO.$arr[58];
731
731
                }
732
732
 
733
 
                if ( $ZBX_TR_EXPR_REPLACE_TO != $expr ){
 
733
 
 
734
                if($ZBX_TR_EXPR_REPLACE_TO != $expr){
734
735
                        error('Incorrect trigger expression. ['.str_replace($ZBX_TR_EXPR_REPLACE_TO, ' ... ', $expr).']');
735
736
                        return false;
736
737
                }
737
738
 
738
 
                return true;
 
739
        return true;
739
740
        }
740
741
 
741
742
 
1178
1179
                if($row){
1179
1180
                        $description = expand_trigger_description_constants($row['description'], $row);
1180
1181
 
1181
 
                        if(is_null($row['host'])) $row['host'] = '{HOSTNAME}';
1182
 
                        $description = str_replace('{HOSTNAME}', $row['host'],$description);
1183
 
 
1184
 
                        if(zbx_strstr($description,'{ITEM.LASTVALUE}')){
 
1182
                        if (zbx_strstr($description, '{HOSTNAME}')) {
 
1183
 
 
1184
                                $functionid = trigger_get_N_functionid($row['expression'], 1);
 
1185
 
 
1186
                                if (isset($functionid)) {
 
1187
                                        $sql = 'SELECT DISTINCT h.host'.
 
1188
                                                        ' FROM functions f,items i,hosts h'.
 
1189
                                                        ' WHERE f.itemid=i.itemid'.
 
1190
                                                                ' AND i.hostid=h.hostid'.
 
1191
                                                                ' AND f.functionid='.$functionid;
 
1192
                                        $host = DBfetch(DBselect($sql));
 
1193
                                        if (is_null($host['host']))
 
1194
                                                $host['host'] = '{HOSTNAME}';
 
1195
                                        $description = str_replace('{HOSTNAME}', $host['host'], $description);
 
1196
                                }
 
1197
                        }
 
1198
 
 
1199
                        if(zbx_strstr($description, '{ITEM.LASTVALUE}')){
1185
1200
                        
1186
1201
                                $functionid=trigger_get_N_functionid($row['expression'], 1);
1187
1202
 
1236
1251
        }
1237
1252
        
1238
1253
        function expand_trigger_description_simple($triggerid){
1239
 
                $sql = 'SELECT DISTINCT t.description,h.host,t.expression,t.triggerid '.
1240
 
                                ' FROM triggers t '.
1241
 
                                        ' LEFT JOIN functions f on t.triggerid=f.triggerid '.
1242
 
                                        ' LEFT JOIN items i on f.itemid=i.itemid '.
1243
 
                                        ' LEFT JOIN hosts h on i.hostid=h.hostid '.
1244
 
                                ' WHERE t.triggerid='.$triggerid;
1245
 
                return expand_trigger_description_by_data(DBfetch(DBselect($sql)));
 
1254
                $sql = 'SELECT DISTINCT h.host,t.description,t.expression,t.triggerid '.
 
1255
                                ' FROM triggers t, functions f, items i, hosts h '.
 
1256
                                ' WHERE f.triggerid=t.triggerid '.
 
1257
                                        ' AND i.itemid=f.itemid '.
 
1258
                                        ' AND h.hostid=i.hostid '.
 
1259
                                        ' AND t.triggerid='.$triggerid;
 
1260
                $trigger = DBfetch(DBselect($sql));
 
1261
                
 
1262
        return expand_trigger_description_by_data($trigger);
1246
1263
        }
1247
1264
 
1248
1265
        function expand_trigger_description($triggerid){
1249
1266
                $description=expand_trigger_description_simple($triggerid);
1250
1267
                $description=htmlspecialchars($description);
1251
 
                return $description;
 
1268
        return $description;
1252
1269
        }
1253
1270
 
1254
1271
        function update_trigger_value_to_unknown_by_hostid($hostids){
1481
1498
                if($event_to_unknown) add_event($triggerid,TRIGGER_VALUE_UNKNOWN);
1482
1499
                reset_items_nextcheck($triggerid);
1483
1500
 
1484
 
                $sql="UPDATE triggers SET";
 
1501
                $sql='UPDATE triggers SET ';
1485
1502
                if(!is_null($expression))       $sql .= ' expression='.zbx_dbstr($expression).',';
1486
1503
                if(!is_null($description))      $sql .= ' description='.zbx_dbstr($description).',';
1487
1504
                if(!is_null($type))                     $sql .= ' type='.$type.',';