The versatile 25-year-old had been without a club since being released by Bolton Wanderers at the end of last season.
"I'm delighted to finally sign because I have been here since the start of pre-season," O'Brien told the official West Ham website.
"It's been a few weeks now and it's gone well. The manager wanted me to sign and as soon as I heard that, there was no real hesitation.
"I'm pleased it's done and dusted."
Allardyce gave a first-team debut to O'Brien when he was manager of Bolton in 2004. O'Brien has since gone on to play for the Irish national side on three occasions.