I have a python script that gets a cluster health as json and sends me a mail. The issue is that the json is not pretty printed. These are the methods I have tried already:
But the output in gmail is still unformatted, somewhat like this
{ "active_primary_shards": 25, "active_shards": 50, "active_shards_percent_as_number": 100.0, "cluster_name": "number_of_pending_tasks": 0, "relocating_shards": 0, "status": "green", "task_max_waiting_in_queue_millis": 0, "timed_out": false, "unassigned_shards": 0 }
Mail was sent to gmail
I can't say for certain, but it would seem like your email-sending code is defaulting to sending an "HTML" email, and in HTML consecutive spaces collapse into one, that way HTML code like:
<p>
This is a paragraph, but it's long so
I'll break to a new line, and indented
so I know it's within the `p` tag, etc.
</p>
Looks like "This is a paragraph, but it's long so I'll break to a new line, and indented so I know it's within the p tag, etc." to the user.
So, I'd say your two options are:
Content-type header as text/plain, orReplace all your spaces with the (non-breaking space) character and newlines with <br> (breaks), for example:
email_body = json.dumps(
health, indent=4, sort_keys=True).replace(' ', ' ').replace('\n', '<br>')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With