~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002101903

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2009-04-05 19:10:27 UTC
  • mfrom: (1.1.9 upstream) (8.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090405191027-lxd44l6jqdcfp2bi
Tags: 1:1.6.4-1
* New upstream release.
* Fix zabbix-frontend-php.template, add missing questions for
  zabbix-server and port (Closes: #522076)
* Loosen up depends for libgnutls (Closes: #522074)

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        if (DBselect('select actionid from actions where actionid='.$actionid.' and '.DBin_node('actionid'))){
31
31
                $result = true;
32
32
                
33
 
                $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
34
 
                $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY);
 
33
                $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,$perm,null,get_current_nodeid(true));
 
34
                $available_groups = get_accessible_groups_by_user($USER_DETAILS,$perm,null,get_current_nodeid(true));
35
35
                
36
36
                $db_result = DBselect('SELECT * FROM conditions WHERE actionid='.$actionid);
37
37
                while(($ac_data = DBfetch($db_result)) && $result){
39
39
 
40
40
                        switch($ac_data['conditiontype']){
41
41
                                case CONDITION_TYPE_HOST_GROUP:
42
 
                                        if(!uint_in_array($ac_data['value'],$available_groups)){
 
42
                                        if(!isset($available_groups[$ac_data['value']])){
43
43
                                                $result = false;
44
44
                                        }
45
45
                                        break;
46
46
                                case CONDITION_TYPE_HOST:
47
47
                                case CONDITION_TYPE_HOST_TEMPLATE:
48
 
                                        if(!uint_in_array($ac_data['value'],$available_hosts)){
 
48
                                        if(!isset($available_hosts[$ac_data['value']])){
49
49
                                                $result = false;
50
50
                                        }
51
51
                                        break;
72
72
 
73
73
        $result = true;
74
74
 
75
 
        $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
76
 
        $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY);
77
 
        
 
75
        $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,get_current_nodeid(true));
 
76
        $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY,null,get_current_nodeid(true));
 
77
 
78
78
        foreach($conditions as $ac_data){
79
79
                if($ac_data['operator'] != 0) continue;
80
80
 
81
81
                switch($ac_data['type']){
82
82
                        case CONDITION_TYPE_HOST_GROUP:
83
 
                                if(!uint_in_array($ac_data['value'],$available_groups)){
 
83
                                if(!isset($available_groups[$ac_data['value']])){
84
84
                                        error(S_INCORRECT_GROUP);
85
85
                                        $result = false;
86
86
                                }
87
87
                                break;
88
88
                        case CONDITION_TYPE_HOST:
89
89
                        case CONDITION_TYPE_HOST_TEMPLATE:
90
 
                                if(!uint_in_array($ac_data['value'],$available_hosts)){
 
90
                                if(!isset($available_hosts[$ac_data['value']])){
91
91
                                        error(S_INCORRECT_HOST);
92
92
                                        $result = false;
93
93
                                }
370
370
        return S_UNKNOWN;
371
371
}
372
372
        
373
 
function        condition_value2str($conditiontype, $value)
374
 
{
375
 
        switch($conditiontype)
376
 
        {
 
373
function condition_value2str($conditiontype, $value){
 
374
        switch($conditiontype){
377
375
                case CONDITION_TYPE_HOST_GROUP:
378
 
                        $str_val = get_hostgroup_by_groupid($value);
379
 
                        $str_val = $str_val['name'];
 
376
                        $group = get_hostgroup_by_groupid($value);
 
377
                        
 
378
                        $str_val = '';
 
379
                        if(id2nodeid($value) != get_current_nodeid()) $str_val = get_node_name_by_elid($value, true);
 
380
                        $str_val.= $group['name'];
380
381
                        break;
381
382
                case CONDITION_TYPE_TRIGGER:
382
383
                        $str_val = expand_trigger_description($value);
383
384
                        break;
384
385
                case CONDITION_TYPE_HOST:
385
386
                case CONDITION_TYPE_HOST_TEMPLATE:
386
 
                        $str_val = get_host_by_hostid($value);
387
 
                        $str_val = $str_val['host'];
 
387
                        $host = get_host_by_hostid($value);                     
 
388
                        $str_val = '';
 
389
                        if(id2nodeid($value) != get_current_nodeid()) $str_val = get_node_name_by_elid($value, true);
 
390
                        $str_val.= $host['host'];
388
391
                        break;
389
392
                case CONDITION_TYPE_TRIGGER_NAME:
390
393
                        $str_val = $value;
429
432
        return '"'.$str_val.'"';
430
433
}
431
434
 
432
 
function        get_condition_desc($conditiontype, $operator, $value)
433
 
{
 
435
function get_condition_desc($conditiontype, $operator, $value){
434
436
        return condition_type2str($conditiontype).' '.
435
437
                condition_operator2str($operator).' '.
436
438
                condition_value2str($conditiontype, $value);
695
697
        return DBexecute("update actions set status=$status where actionid=$actionid");
696
698
}
697
699
 
698
 
function validate_condition($conditiontype, $value)
699
 
{
 
700
function validate_condition($conditiontype, $value){
700
701
        global $USER_DETAILS;
701
702
 
702
 
        switch($conditiontype)
703
 
        {
 
703
        switch($conditiontype){
704
704
                case CONDITION_TYPE_HOST_GROUP:
705
 
                        if(!uint_in_array($value,
706
 
                                get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY)))
707
 
                        {
 
705
                        $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY,null,get_current_nodeid(true));
 
706
                        if(!isset($available_groups[$value])){
708
707
                                error(S_INCORRECT_GROUP);
709
708
                                return false;
710
709
                        }
711
710
                        break;
712
711
                case CONDITION_TYPE_HOST_TEMPLATE:
713
 
                        if(!uint_in_array($value,
714
 
                                get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY)))
715
 
                        {
716
 
                                error(S_INCORRECT_GROUP);
 
712
                        $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,get_current_nodeid(true));
 
713
                        if(!isset($available_hosts[$value])){
 
714
                                error(S_INCORRECT_HOST);
717
715
                                return false;
718
716
                        }
719
717
                        break;
726
724
                        }
727
725
                        break;
728
726
                case CONDITION_TYPE_HOST:
729
 
                        if(!uint_in_array($value,
730
 
                                get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY)))
731
 
                        {
 
727
                        $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,get_current_nodeid(true));
 
728
                        if(!isset($available_hosts[$value])){
732
729
                                error(S_INCORRECT_HOST);
733
730
                                return false;
734
731
                        }
735
732
                        break;
736
733
                case CONDITION_TYPE_TIME_PERIOD:
737
 
                        if( !validate_period($value) )
738
 
                        {
 
734
                        if( !validate_period($value) ){
739
735
                                error(S_INCORRECT_PERIOD.' ['.$value.']');
740
736
                                return false;
741
737
                        }
742
738
                        break;
743
739
                case CONDITION_TYPE_DHOST_IP:
744
 
                        if( !validate_ip_range($value) )
745
 
                        {
 
740
                        if( !validate_ip_range($value) ){
746
741
                                error(S_INCORRECT_IP.' ['.$value.']');
747
742
                                return false;
748
743
                        }
749
744
                        break;
750
745
                case CONDITION_TYPE_DSERVICE_TYPE:
751
 
                        if( S_UNKNOWN == discovery_check_type2str($value) )
752
 
                        {
 
746
                        if( S_UNKNOWN == discovery_check_type2str($value) ){
753
747
                                error(S_INCORRECT_DISCOVERY_CHECK);
754
748
                                return false;
755
749
                        }
756
750
                        break;
757
751
                case CONDITION_TYPE_DSERVICE_PORT:
758
 
                        if( !validate_port_list($value) )
759
 
                        {
 
752
                        if( !validate_port_list($value) ){
760
753
                                error(S_INCORRECT_PORT.' ['.$value.']');
761
754
                                return false;
762
755
                        }
763
756
                        break;
764
757
                case CONDITION_TYPE_DSTATUS:
765
 
                        if( S_UNKNOWN == discovery_object_status2str($value) )
766
 
                        {
 
758
                        if( S_UNKNOWN == discovery_object_status2str($value) ){
767
759
                                error(S_INCORRECT_DISCOVERY_STATUS);
768
760
                                return false;
769
761
                        }
893
885
}
894
886
 
895
887
function get_history_of_actions($start,$num,$sql_cond=''){
896
 
        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
 
888
        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY);
897
889
 
898
890
        $table = new CTableInfo(S_NO_ACTIONS_FOUND);
899
891
        $table->SetHeader(array(
915
907
                                ' AND '.DBcondition('e.objectid',$available_triggers).
916
908
                                ' AND '.DBin_node('a.alertid').
917
909
                        order_by('a.clock,a.alertid,mt.description,a.sendto,a.status,a.retries');
918
 
 
919
910
        $result=DBselect($sql,10*$start+$num);
920
911
                
921
912
        $col=0;
966
957
        
967
958
// Author: Aly
968
959
function get_action_msgs_for_event($eventid){
969
 
        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
 
960
        $hostids = array();
 
961
        $sql = 'SELECT DISTINCT i.hostid '.
 
962
                        ' FROM events e, functions f, items i '.
 
963
                        ' WHERE e.eventid='.$eventid.
 
964
                                ' AND e.object='.EVENT_SOURCE_TRIGGERS.
 
965
                                ' AND f.triggerid=e.objectid '.
 
966
                                ' AND i.itemid=f.itemid';
 
967
        if($host = DBfetch(DBselect($sql,1))){
 
968
                $hostids[$host['hostid']] = $host['hostid'];
 
969
        }
 
970
        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, $hostids);
970
971
 
971
972
        $table = new CTableInfo(S_NO_ACTIONS_FOUND);
972
973
        $table->SetHeader(array(
1041
1042
 
1042
1043
// Author: Aly
1043
1044
function get_action_cmds_for_event($eventid){
1044
 
        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
 
1045
        $hostids = array();
 
1046
        $sql = 'SELECT DISTINCT i.hostid '.
 
1047
                        ' FROM events e, functions f, items i '.
 
1048
                        ' WHERE e.eventid='.$eventid.
 
1049
                                ' AND e.object='.EVENT_SOURCE_TRIGGERS.
 
1050
                                ' AND f.triggerid=e.objectid '.
 
1051
                                ' AND i.itemid=f.itemid';
 
1052
        if($host = DBfetch(DBselect($sql,1))){
 
1053
                $hostids[$host['hostid']] = $host['hostid'];
 
1054
        }
 
1055
        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, $hostids);
1045
1056
 
1046
1057
        $table = new CTableInfo(S_NO_ACTIONS_FOUND);
1047
1058
        $table->SetHeader(array(
1104
1115
 
1105
1116
// Author: Aly
1106
1117
function get_actions_hint_by_eventid($eventid,$status=NULL){
1107
 
        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
 
1118
        $hostids = array();
 
1119
        $sql = 'SELECT DISTINCT i.hostid '.
 
1120
                        ' FROM events e, functions f, items i '.
 
1121
                        ' WHERE e.eventid='.$eventid.
 
1122
                                ' AND e.object='.EVENT_SOURCE_TRIGGERS.
 
1123
                                ' AND f.triggerid=e.objectid '.
 
1124
                                ' AND i.itemid=f.itemid';
 
1125
        if($host = DBfetch(DBselect($sql,1))){
 
1126
                $hostids[$host['hostid']] = $host['hostid'];
 
1127
        }
 
1128
        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, $hostids);
1108
1129
        
1109
1130
        $tab_hint = new CTableInfo(S_NO_ACTIONS_FOUND);
1110
1131
        $tab_hint->AddOption('style', 'width: 300px;');