Good work!
You triggered my interest and got me looking at this (I did need some diversion from my horrible
stability issue 
). Here is my take at it:
Code:
#!/bin/bash
declare MCA_ERRORS
MCA_ERRORS="$(cat /var/log/messages | egrep "$(date -v -1H "+%b %e %H").*$(hostname -s) MCA.*")"
[[ ! -z "${MCA_ERRORS}" ]] && mail -s "TrueNAS $(hostname): Alerts" youremail@outlook.com <<< "MCA Errors were found in /var/log/messages:\n${MCA_ERRORS}"
I didn't try or tested it yet, but it should be possible to get it working like this...
Specifics are:
- One language only (bash). Yours is Python and some shell by using os.system().
- I think yours might email you every 10 seconds, once MCA errors are found, as it checks the whole /var/log/messages for MCA each time ;) I tried to solve this by by only checking once per hour and only the last hour (you could probably modify this to make it more frequent)
- My /var/log/messages contains entries like "Nov 28 09:14:19 data Features=0x178bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,MMX,FXSR,SSE,SSE2,HTT>", which aren't errors. By making the grep more specific, these should be excluded as well...
- It will email the MCA errors for the previous hour to your email address
Flaws:
- It may miss errors shortly before a logrotate. Not sure yet how to properly / efficiently catch these.
- If you create your crontab like 1 second before the hour, perhaps it could happen that crontab is delayed and does the check for the "wrong" hour, so best set it somewhere not around the hour (like at ??h30m)
- I tried to make it send emails similarly to "official" TrueNAS emails, but I didn't succeed yet in making mail send emails with a custom name in the from field. In my TrueNAS install, TrueNAS emails me with the short hostname in the from field, instead of just the email address.
- Perhaps a variable exists for which email address to email to, so that the script doesn't need to be edited to work?
Regarding crontab:
Sorry, I didn't really look at your crontab issue yet, but I think TrueNAS prefers that you use the GUI -> Tasks instead of the crontab command. Not sure if that is because the crontab command is special / different or crippled somehow. But I suggest you try that.
And now I'm back to figuring out what's
wrong with my server 
Assistance is always welcome
