zabbix_export:
  version: '7.0'
  media_types:
    - name: 'Maria Assistant'
      type: WEBHOOK
      parameters:
        - name: Message
          value: '{ALERT.MESSAGE}'
        - name: Subject
          value: '{ALERT.SUBJECT}'
        - name: To
          value: '{ALERT.SENDTO}'
        - name: Token
          value: MariaHook-PublicSecure-2026.
        - name: URL
          value: 'https://api.ccaceresoln.com/webhook/zabbix'
      script: |
        try {
            var params = JSON.parse(value),
                req = new HttpRequest(),
                data = {};
        
            req.addHeader('Content-Type: application/json');
            req.addHeader('Authorization: Bearer ' + params.Token);
        
            data.alert_subject = params.Subject;
            data.alert_message = params.Message;
            data.fcm_token = params.To; // Aquí Zabbix pondrá el token de tu app
        
            var response = req.post(params.URL, JSON.stringify(data));
        
            if (req.getStatus() !== 200) {
                throw 'Error HTTP: ' + req.getStatus() + ' - ' + response;
            }
        
            return 'OK';
        } catch (error) {
            Zabbix.log(3, 'Maria Webhook Error: ' + error);
            throw 'Error enviando a Maria Assistant: ' + error;
        }
      message_templates:
        - event_source: TRIGGERS
          operation_mode: PROBLEM
          subject: 'Problem: {EVENT.NAME}'
          message: |
            Problem started at {EVENT.TIME} on {EVENT.DATE}
            Problem name: {EVENT.NAME}
            Host: {HOST.NAME}
            Severity: {EVENT.SEVERITY}