I see others in the forum are having random OAuth2 token issues. This happens randomly to me as well so I created scripts to send alerts via email and notifications in Nagios.
Hopefully this can help others as it has helped us.
Using a combination of cron jobs I pull info from the following table in the osTicket database:
osticket.ost_email_account
For the email account in question (in my case id 3), the important fields are:
last_error
&
last_activity
Once the information is in text files I run additional scripts based on the values.
If last_error shows a value, a script sends me a warning via email. Sometimes the issue is temporary and resolves quickly.
If last_activity starts to lag, I get another email plus a critical warning shows in Nagios. When this happens, it usually means there's a real issue. Reauthenticating usually resolves it.
Pasting the basics below:
The “osticket.ost_email_account” table in the osTicket database: