Ubuntu 22.04 + Zabbix6.0 + iTOP3.0

Zabbix自动创建工单到iTOP

一、安装apache2和mysql(mariadb)

Sudo apt-get install apache2

Sudo apt-get install mariadb-server

二、修改mysql(mariadb)的root密码,创建itop数据库和角色

首次登录直接输入mysql,回车即可,因为root没有密码

然后修改root密码,创建

Mysql>alter user 'root'@'localhost' identified by '你的密码';#此处修改mysql root用户密码

Mysql>create database itopdb;#自定义名称,我这里用的是itopdb

Mysql>create user 'itopdbsa'@'localhost' identified by 'itopdbsa用户的密码';

Mysql>grant all privileges on itopdb.* to itopdbsa@localhost;#将itopdb数据库的权限给itopdbsa角色

Mysql>flush privileges;#刷新权限

Mysql>quit;

三、安装apache2,php-soap,graphviz,php,php-zip

Itop2.7 以前版本建议php7

Itop3.0以后版本建议php8

四、itop官网下载zip包,上传到服务器后解压缩

下载地址:iTop - IT Service Management & CMDB download | SourceForge.net

解压缩后会有web目录和目录外的几个文件,web目录可以改名,我改为了itsm

将itsm目录复制到/var/www/html/下(关于iTOP的安装不再赘述,基本都是“下一步”)

将web目录给权限chown www-data /var/www/html/itsm -R

修改apache2.conf文件,设置itop目录允许重载

查找apache2.conf文件位置,一般在/etc/apache2/apache2.conf

find / -name apache2.conf

在apache2.conf中添加以下代码(Directory后面根据实际路径修改,我的是itop目录)以允许itop目录重载

重点是AllowOverride ALL

<Directory /var/www/html/itop>

        AllowOverride ALL

        Require all granted

</Directory>

重启apache服务

systemctl restart apache2

五、下载itop 的yaml文件

可将下列代码保存为yaml文件导入

zabbix_export:
  version: '6.0'
  date: '2024-01-19T06:18:08Z'
  media_types:
    - name: iTop
      type: WEBHOOK
      parameters:
        - name: alert_message
          value: '{ALERT.MESSAGE}'
        - name: alert_subject
          value: '告警:{ALERT.SUBJECT}'
        - name: event_recovery_value
          value: '{EVENT.RECOVERY.VALUE}'
        - name: event_source
          value: '1'
        - name: event_update_status
          value: '{EVENT.UPDATE.STATUS}'
        - name: event_value
          value: '{EVENT.VALUE}'
        - name: itop_api_version
          value: '1.3'
        - name: itop_class
          value: UserRequest
        - name: itop_comment
          value: 'Created by Zabbix action {ACTION.NAME}'
        - name: itop_id
          value: '{EVENT.TAGS.__zbx_itop_id}'
        - name: itop_log
          value: private_log
        - name: itop_organization_id
          value: '2'
        - name: itop_password
          value: yourpassword
        - name: itop_url
          value: 'http://127.0.0.1/itsm'
        - name: itop_user
          value: itop-zabbixuser
      script: |
        var Itop = {
            params: {},
        
            setParams: function (params) {
                if (typeof params !== 'object') {
                    return;
                }
        
                if (params.log !== 'private_log' && params.log !== 'public_log') {
                    throw 'Incorrect "itop_log" parameter given: ' + params.log + '\nMust be "private_log" or "public_log".';
                }
        
                Itop.params = params;
                if (typeof Itop.params.url === 'string') {
                    if (!Itop.params.url.endsWith('/')) {
                        Itop.params.url += '/';
                    }
        
                    Itop.params.url += 'webservices/rest.php?version=' + encodeURIComponent(Itop.params.api_version);
                }
            },
        
            setProxy: function (HTTPProxy) {
                Itop.HTTPProxy = HTTPProxy;
            },
        
            setCreatePayload: function () {
                json_data.operation = 'core/create';
                json_data.fields.org_id = Itop.params.organization_id;
                json_data.fields.title = params.alert_subject;
                json_data.fields.description = params.alert_message.replace('<', '&lt;')
                    .replace('>', '&gt;')
                    .replace(/(?:\r\n|\r|\n)/g, '<br>');
            },
        
            setUpdatePayload: function () {
                json_data.operation = 'core/update';
                json_data.key = Itop.params.id;
                json_data.fields.title = params.alert_subject;
                json_data.fields[Itop.params.log] = {
                    add_item: {
                        message: params.alert_subject + '\n' + params.alert_message,
                        format: 'text'
                    }
                };
            },
        
            request: function (data) {
                ['url', 'user', 'password', 'organization_id', 'class', 'api_version', 'id'].forEach(function (field) {
                    if (typeof Itop.params !== 'object' || typeof Itop.params[field] === 'undefined'
                            || Itop.params[field] === '' ) {
                        throw 'Required Itop param is not set: "itop_' + field + '".';
                    }
                });
        
                var response,
                    url = Itop.params.url,
                    request = new HttpRequest(),
                    object;
        
                request.addHeader('Content-Type: multipart/form-data');
                request.addHeader('Authorization: Basic ' + btoa(Itop.params.user + ':' + Itop.params.password));
        
                if (Itop.HTTPProxy) {
                    request.setProxy(Itop.HTTPProxy);
                }
        
                if (typeof data !== 'undefined') {
                    data = JSON.stringify(data);
                }
        
                Zabbix.log(4, '[ iTop Webhook ] Sending request: ' + url + '&json_data=' + data);
        
                response = request.post(url + '&json_data=' + encodeURIComponent(data));
        
                Zabbix.log(4, '[ iTop Webhook ] Received response with status code ' + request.getStatus() + '\n' + response);
        
                try {
                    response = JSON.parse(response);
                }
                catch (error) {
                    Zabbix.log(4, '[ iTop Webhook ] Failed to parse response received from iTop');
                    throw 'Failed to parse response received from iTop.\nRequest status code ' +
                            request.getStatus() + '. Check debug log for more information.';
                }
        
                if (request.getStatus() < 200 || request.getStatus() >= 300) {
                    throw 'Request failed with status code ' + request.getStatus() + '. Check debug log for more information.';
                }
                else if (typeof response.code !== 'undefined' && response.code !== 0) {
                    throw 'Request failed with iTop code ' + response.code + ': ' +
                            JSON.stringify(response.message) + '. Check debug log for more information.';
                }
                else {
                    Object.keys(response.objects)
                        .forEach(function (key) {
                            object = response.objects[key];
                        });
            
                    return {
                        status: request.getStatus(),
                        response: object.fields
                    };
                }
            }
        };
        
        try {
            var params = JSON.parse(value),
                json_data = {},
                itop_params = {},
                result = {tags: {}},
                required_params = [
                    'alert_subject', 'summary', 'event_recovery_value',
                    'event_source', 'event_value', 'action_name'
                ];
        
            Object.keys(params)
                .forEach(function (key) {
                    if (key.startsWith('itop_')) {
                        itop_params[key.substring(5)] = params[key];
                    }
                    else if (required_params.indexOf(key) !== -1 && params[key] === '') {
                        throw 'Parameter "' + key + '" can\'t be empty.';
                    }
                });
        
            if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
                throw 'Incorrect "event_source" parameter given: ' + params.event_source + '\nMust be 0-3.';
            }
        
            // Check {EVENT.VALUE} for trigger-based and internal events.
            if (params.event_value !== '0' && params.event_value !== '1'
                    && (params.event_source === '0' || params.event_source === '3')) {
                throw 'Incorrect "event_value" parameter given: ' + params.event_value + '\nMust be 0 or 1.';
            }
        
            // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
            if (params.event_update_status !== '0' && params.event_update_status !== '1' && params.event_source === '0') {
                throw 'Incorrect "event_update_status" parameter given: ' + params.event_update_status + '\nMust be 0 or 1.';
            }
        
            if (params.event_source !== '0' && params.event_recovery_value === '0') {
                throw 'Recovery operations are supported only for trigger-based actions.';
            }
        
            Itop.setParams(itop_params);
            Itop.setProxy(params.HTTPProxy);
        
            json_data.operation = '';
            json_data.class = Itop.params.class;
            json_data.comment = Itop.params.comment;
            json_data.output_fields = 'id, friendlyname';
            json_data.fields = {};
        
            // Create issue for non trigger-based events.
            if (params.event_source !== '0' && params.event_recovery_value !== '0') {
                Itop.setCreatePayload();
                Itop.request(json_data);
            }
            // Create issue for trigger-based events.
            else if (params.event_value === '1' && params.event_update_status === '0'
                    && Itop.params.id === '{EVENT.TAGS.__zbx_itop_id}') {
                Itop.setCreatePayload();
        
                var response = Itop.request(json_data);
        
                result.tags.__zbx_itop_id = response.response.id;
                result.tags.__zbx_itop_key = response.response.friendlyname;
                result.tags.__zbx_itop_link = params.itop_url + (params.itop_url.endsWith('/') ? '' : '/') +
                        'pages/UI.php?operation=details&class=' + encodeURIComponent(Itop.params.class) + '&id=' +
                        encodeURIComponent(response.response.id);
            }
            // Update created issue for trigger-based event.
            else {
                if (Itop.params.id === '{EVENT.TAGS.__zbx_itop_id}') {
                    throw 'Incorrect iTop ticket ID given: ' + Itop.params.id;
                }
                Itop.setUpdatePayload();
                Itop.request(json_data);
            }
        
            return JSON.stringify(result);
        }
        catch (error) {
            Zabbix.log(3, '[ iTop Webhook ] ERROR: ' + error);
            throw 'Sending failed: ' + error;
        }
      process_tags: 'YES'
      show_event_menu: 'YES'
      event_menu_url: '{EVENT.TAGS.__zbx_itop_link}'
      event_menu_name: 'iTop: {EVENT.TAGS.__zbx_itop_key}'
      message_templates:
        - event_source: TRIGGERS
          operation_mode: PROBLEM
          subject: '[{EVENT.STATUS}] {EVENT.NAME}'
          message: |
            告警时间: {EVENT.DATE}-- {EVENT.TIME}
            
            告警项:: {EVENT.NAME}
            
            影响主机: {HOST.NAME} - {HOST.IP}
            
            严重性: {EVENT.SEVERITY}
            ---
            
            事件 ID: {EVENT.ID}
            {TRIGGER.URL}

导入yaml文件后,zabbix 报警媒介中,参照以下设置

a18c3d8a79a54aaf886cb839bd9c1f49.png

上图中填写的账号是itop中的账号,此账号在itop中须具备REST Services User权限,方法:

itop中点击“管理”-“用户账户”,编辑此账户并添加REST Services User权限

此账号的id,可以在itop中的“数据管理”→“组织”中,点击账号从属的组织后,在浏览器地址栏进行查看

编辑“脚本”内容,粘贴下列文本

请粘贴下列文本:

文本开始:

var Itop = {
    params: {},

    setParams: function (params) {
        if (typeof params !== 'object') {
            return;
        }

        if (params.log !== 'private_log' && params.log !== 'public_log') {
            throw 'Incorrect "itop_log" parameter given: ' + params.log + '\nMust be "private_log" or "public_log".';
        }

        Itop.params = params;
        if (typeof Itop.params.url === 'string') {
            if (!Itop.params.url.endsWith('/')) {
                Itop.params.url += '/';
            }

            Itop.params.url += 'webservices/rest.php?version=' + encodeURIComponent(Itop.params.api_version);
        }
    },

    setProxy: function (HTTPProxy) {
        Itop.HTTPProxy = HTTPProxy;
    },

    setCreatePayload: function () {
        json_data.operation = 'core/create';
        json_data.fields.org_id = Itop.params.organization_id;
        json_data.fields.title = params.alert_subject;
        json_data.fields.description = params.alert_message.replace('<', '&lt;')
            .replace('>', '&gt;')
            .replace(/(?:\r\n|\r|\n)/g, '<br>');
    },

    setUpdatePayload: function () {
        json_data.operation = 'core/update';
        json_data.key = Itop.params.id;
        json_data.fields.title = params.alert_subject;
        json_data.fields[Itop.params.log] = {
            add_item: {
                message: params.alert_subject + '\n' + params.alert_message,
                format: 'text'
            }
        };
    },

    request: function (data) {
        ['url', 'user', 'password', 'organization_id', 'class', 'api_version', 'id'].forEach(function (field) {
            if (typeof Itop.params !== 'object' || typeof Itop.params[field] === 'undefined'
                    || Itop.params[field] === '' ) {
                throw 'Required Itop param is not set: "itop_' + field + '".';
            }
        });

        var response,
            url = Itop.params.url,
            request = new HttpRequest(),
            object;

        request.addHeader('Content-Type: multipart/form-data');
        request.addHeader('Authorization: Basic ' + btoa(Itop.params.user + ':' + Itop.params.password));

        if (Itop.HTTPProxy) {
            request.setProxy(Itop.HTTPProxy);
        }

        if (typeof data !== 'undefined') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, '[ iTop Webhook ] Sending request: ' + url + '&json_data=' + data);

        response = request.post(url + '&json_data=' + encodeURIComponent(data));

        Zabbix.log(4, '[ iTop Webhook ] Received response with status code ' + request.getStatus() + '\n' + response);

        try {
            response = JSON.parse(response);
        }
        catch (error) {
            Zabbix.log(4, '[ iTop Webhook ] Failed to parse response received from iTop');
            throw 'Failed to parse response received from iTop.\nRequest status code ' +
                    request.getStatus() + '. Check debug log for more information.';
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            throw 'Request failed with status code ' + request.getStatus() + '. Check debug log for more information.';
        }
        else if (typeof response.code !== 'undefined' && response.code !== 0) {
            throw 'Request failed with iTop code ' + response.code + ': ' +
                    JSON.stringify(response.message) + '. Check debug log for more information.';
        }
        else {
            Object.keys(response.objects)
                .forEach(function (key) {
                    object = response.objects[key];
                });
    
            return {
                status: request.getStatus(),
                response: object.fields
            };
        }
    }
};

try {
    var params = JSON.parse(value),
        json_data = {},
        itop_params = {},
        result = {tags: {}},
        required_params = [
            'alert_subject', 'summary', 'event_recovery_value',
            'event_source', 'event_value', 'action_name'
        ];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith('itop_')) {
                itop_params[key.substring(5)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '') {
                throw 'Parameter "' + key + '" can\'t be empty.';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw 'Incorrect "event_source" parameter given: ' + params.event_source + '\nMust be 0-3.';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== '0' && params.event_value !== '1'
            && (params.event_source === '0' || params.event_source === '3')) {
        throw 'Incorrect "event_value" parameter given: ' + params.event_value + '\nMust be 0 or 1.';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== '0' && params.event_update_status !== '1' && params.event_source === '0') {
        throw 'Incorrect "event_update_status" parameter given: ' + params.event_update_status + '\nMust be 0 or 1.';
    }

    if (params.event_source !== '0' && params.event_recovery_value === '0') {
        throw 'Recovery operations are supported only for trigger-based actions.';
    }

    Itop.setParams(itop_params);
    Itop.setProxy(params.HTTPProxy);

    json_data.operation = '';
    json_data.class = Itop.params.class;
    json_data.comment = Itop.params.comment;
    json_data.output_fields = 'id, friendlyname';
    json_data.fields = {};

    // Create issue for non trigger-based events.
    if (params.event_source !== '0' && params.event_recovery_value !== '0') {
        Itop.setCreatePayload();
        Itop.request(json_data);
    }
    // Create issue for trigger-based events.
    else if (params.event_value === '1' && params.event_update_status === '0'
            && Itop.params.id === '{EVENT.TAGS.__zbx_itop_id}') {
        Itop.setCreatePayload();

        var response = Itop.request(json_data);

        result.tags.__zbx_itop_id = response.response.id;
        result.tags.__zbx_itop_key = response.response.friendlyname;
        result.tags.__zbx_itop_link = params.itop_url + (params.itop_url.endsWith('/') ? '' : '/') +
                'pages/UI.php?operation=details&class=' + encodeURIComponent(Itop.params.class) + '&id=' +
                encodeURIComponent(response.response.id);
    }
    // Update created issue for trigger-based event.
    else {
        if (Itop.params.id === '{EVENT.TAGS.__zbx_itop_id}') {
            throw 'Incorrect iTop ticket ID given: ' + Itop.params.id;
        }
        Itop.setUpdatePayload();
        Itop.request(json_data);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, '[ iTop Webhook ] ERROR: ' + error);
    throw 'Sending failed: ' + error;
}

附:

六、修改itop欢迎文字,修改文件(修改前记得备份)

/var/www/html/itsm/dictionaries/zh_cn.dictionary.itop.ui.php

/var/www/html/itsm/env-production/dictionaries/zh-cn.dict.php

修改itop图片及logo

5dbc80ba2409433ea456cc31ed88ad23.png

七:修改Zabbix6.0 logo及login页面

修改brand.conf.php文件,如果没有

需要创建一个 PHP 文件并将其保存为 zabbix/local/conf/brand.conf.php

我的目录在/usr/share/zabbix/local/conf/brand.conf.php

需自行搜索zabbix/local 目录,将来的三个图片也需放在zabbix目录下,和local同级

我建立的目录是zabbix/logo,三张图片的文件名参照

custom_logo.png

custom_logo_sidebar.png

custom_logo_sidebar_compact.png

brand.conf.php文件内容参考:

<?php
return [
        'BRAND_LOGO' => './logo/custom_logo.png',
        'BRAND_LOGO_SIDEBAR' => './logo/custom_logo_sidebar.png',
        'BRAND_LOGO_SIDEBAR_COMPACT' => './logo/custom_logo_sidebar_compact.png',
        'BRAND_FOOTER' => '互联网安全@天津 2023',
        'BRAND_HELP_URL' => 'https://www.zabbix.com/documentation/6.0/zh/manual/introduction/features'
];
 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值