There are some HDD SMART parameters about the critical situation with HDD.
It is "Reallocated Sector Count", "Reallocated Event Count", "Current Pending Sector Count", "Offline Uncorrectable Sector Count".
Can you do these parameters in your software?