Does anyone now how I can use the API to check to see the status of a service?

I need to write a program that checks the service every so often and if the status is paused or stopped I need to send an alert.

Thanks.