Automatically restarting Cloudflared when internet is restored

I had a internesting issue this morning. We had a bad storm move though and we lost internet. I have all my routers, and pi-hole on UPS and protected. But the Cloudfared daemon would not service requests after the internet was restored. I had to manually stop and restart it. Before I restarted I was able to confirm that local DNS was being resolved from cache but anything upstream would hit the Cloudflared and there would be no return.

I was wondering if anyone has written a script that would test for a loss of internet on their pi-hole? I was thinking if I could detect this loss and restoration of internet I could then restart the cloudflard service.