Improve query for alarmed metrics

Use joins to change three queries into one. Add a test that
showed a bug in the previous code

Changed to use a simpler way of creating the SubAlarm when
queried

Change-Id: I44ed4a6283b156d387564d1b802f2cd06f59bc8c