Detecting unconfirmed double spends using bitcoind
bitcoind has a debugging option named mempoolrej. You can enable this by adding

debug=mempoolrej


to your bitcoin.conf file.

This debugging options tells bitcoind to print out information about the transactions that it rejects from the mempool, including why. You can thus enable this option and tail and grep the debug.log file looking for the string

was not accepted


This string is only found in the mempoolrej message which is of the form 

&lt;txid&gt; from peer=&lt;peer id&gt; was not accepted: &lt;reason&gt;


The reason you are looking for is txn-mempool-conflict. So you can tail and grep for the entire string:

was not accepted: txn-mempool-conflict


Then with some bash-fu you can make this notify you whenever this string is found in the debug.log file.