Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angle brackets (“<” and “>”) are encoded as u003c and u003e in JSON output #316

Open
ckotte opened this issue Sep 14, 2020 · 1 comment

Comments

@ckotte
Copy link

ckotte commented Sep 14, 2020

I get this..

{
    "job": {
        "command": "/backup/container-backup/container-backup.sh -p syncthing-data u003eu003e /home/jobber/backup-syncthing-data.log 2u003eu003e /home/jobber/backup-syncthing-data.log",
        "name": "backup_syncthing-data",
        "status": "Good",
        "time": "0 0 3 * * *"
    },
    "startTime": "Sep 14 03:00:00 2020",
    "stderr": "",
    "stderr_base64": false,
    "stdout": "",
    "stdout_base64": false,
    "succeeded": true,
    "user": "root"
}

This is the "prettified" JSON output, but it looks similar when I don't use

#!/bin/bash
...
read stdin
...
json=$(echo "$stdin" | python3 -m json.tool)
sendmail ${MAIL_ADDRESS} <<MAIL_END
Subject: ${subject}
From: jobber <${MAIL_ADDRESS}>

$text

$json
MAIL_END

.. but the command is /backup/container-backup/container-backup.sh -p syncthing-data >> /home/jobber/backup-syncthing-data.log 2>> /home/jobber/backup-syncthing-data.log

I read that this behavior can be disabled in "Go's JSON marshaller" (https://discuss.elastic.co/t/beats-encodes-angle-brackets-and-as-u003c-and-u003e-in-json-output/60667).

@ckotte ckotte changed the title Angle brackets (“<” and “>”) are encoded as \u003c and \u003e in JSON output Angle brackets (“<” and “>”) are encoded as u003c and u003e in JSON output Sep 14, 2020
@ckotte
Copy link
Author

ckotte commented Oct 17, 2020

While trying to implement json.NewEncoder I found out that this is already implemented in func SerializeRunRec and that this is controlled via the undocumented variable runRecFormatVersion.

I can fix this by using runRecFormatVersion: 1.4:

  test:
    cmd: ls / >> ~/log/test.log
    time: '0 */1 * * * *'
    onError: Continue
    notifyOnSuccess:
      - type: program
        path: /usr/local/bin/send_jobber_email.sh
        runRecFormatVersion: 1.4
    notifyOnError:
      - type: program
        path: /usr/local/bin/send_jobber_email.sh
        runRecFormatVersion: 1.4

Before:

{
    "job": {
        "command": "ls / u003eu003e ~/log/test.log",
        "name": "letsencrypt_renewal_test",
        "status": "Good",
        "time": "0 */1 * * * *"
    },
    "startTime": "Oct 17 18:27:00 2020",
    "stderr": "",
    "stderr_base64": false,
    "stdout": "",
    "stdout_base64": false,
    "succeeded": true,
    "user": "jobber"
}

After:

{
    "fate": 0,
    "job": {
        "command": "ls / >> ~/log/test.log",
        "name": "letsencrypt_renewal_test",
        "status": "Good",
        "time": "0 */1 * * * *"
    },
    "startTime": 1602952140,
    "stderr": "",
    "stdout": "",
    "succeeded": true,
    "user": "jobber",
    "version": "1.4"
}

However, the startTime is in Unix format now and a few new keys are added as well.

@dshearer I guess runRecFormatVersion is not documented because func SerializeRunRec and the new RunRec are still WIP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant