What diagnostics are you looking to perform? Display a message on the HMI screen in case of some error (broken wire/short cicuit, etc)?
There is some built in functionality to do this in Step 7, called Report System Error. Assuming you are using Simatic Manager, you can activate this from the HW Config by selecting the CPU, and then going to Options -> Report System Error. A bunch of configuration is possible, but the only thing you NEED to do is hit the generate button at the bottom of the new window.
It will automatically create a PLC alarm for any diagnostic event in the system, whether its a HW error, a network error, or a program error. It generates an FB and inserts it into a few different OB's automatically. The only trick, I think, is that it might only work with a Siemens HMI. I'm not sure if controller alarms can be read by other vendors systems.