icinga-hubot-script
Version:
A hubot script that takes notification messages from Icinga and post them to any IRC channel
135 lines (110 loc) • 5.29 kB
text/coffeescript
chai = require 'chai'
sinon = require 'sinon'
chai.use require 'sinon-chai'
expect = chai.expect
MessageCreator = require '../src/message_creator'
describe 'MessageCreator', ->
beforeEach ->
= new MessageCreator()
=
hostname: ->
return 'any hostname'
hostState: ->
return 1
serviceState: ->
return 2
serviceDescription: ->
return 'service description'
isHostNotification: ->
return false
isServiceNotification: ->
return false
isProblem: ->
return false
isRecovery: ->
return false
hostActionUrl: ->
return ''
serviceActionUrl: ->
return 'service_action_url'
comment: ->
return 'comment'
author: ->
return 'author'
isAcknowledgement: ->
return false
isDowntimeStart: ->
return false
isDowntimeCancelled: ->
return false
describe 'messages()', ->
describe 'is a problem', ->
beforeEach ->
.isProblem = ->
return true
it 'message should contain problem message', ->
expect(.messages().join(' ')).to.match(/Houston/)
describe 'is a host notification', ->
beforeEach ->
.isHostNotification = ->
return true
.hostActionUrl = ->
return 'any_host_notes_url'
it 'message contains the hostname if it is a host notification', ->
expect(.messages().join(' ')).to.match(/any hostname/)
describe 'is a service notification', ->
beforeEach ->
.isServiceNotification = ->
return true
.serviceActionUrl = ->
return 'any_service_notes_url'
it 'message contains the service name if it is a service notification', ->
expect(.messages().join(' ')).to.match(/service description/)
it 'message contains the service notes url', ->
expect(.messages().join(' ')).to.match(/any_service_notes_url/)
it 'message does not contain the service notes url, if it is not provided by icinga', ->
.serviceActionUrl = ->
return undefined
expect(.messages().join(' ')).to.not.match(/undefined/)
describe 'isRecovery', ->
beforeEach ->
.isRecovery = ->
return true
it 'message contain problem message', ->
expect(.messages().join(' ')).to.match(/Problem solved/)
it 'message contains the hostname if it is a host notification', ->
.isHostNotification = ->
return true
expect(.messages().join(' ')).to.match(/any hostname/)
it 'message contains the service name if it is a service notification', ->
.isServiceNotification = ->
return true
expect(.messages().join(' ')).to.match(/service description/)
it 'message does not contain the service action url', ->
.isServiceNotification = ->
return true
expect(.messages().join(' ')).to.not.match(/service_action_url/)
describe 'isAcknowledgement', ->
beforeEach ->
.isAcknowledgement = ->
return true
it 'message should contains the user who takes care of a problem', ->
expect(.messages().join(' ')).to.match(/author/)
it 'message should contain the problem which is taken care of', ->
expect(.messages().join(' ')).to.match(/Critical/)
it 'message should contains the message the user left behind', ->
expect(.messages().join(' ')).to.match(/comment/)
describe 'isDowntimeStart', ->
it 'message contains downtime start string if it is a downtime start icinga notification', ->
.isDowntimeStart = ->
return true
expect(.messages().join(' ')).to.match(/Downtime started/)
it 'message does not contain downtime start string if it is not a downtime start icinga notification', ->
expect(.messages().join(' ')).to.not.match(/Downtime started/)
describe 'isDowntimeCancelled', ->
it 'message contains downtime cancelled string if it is a downtime cancelled icinga notification', ->
.isDowntimeCancelled = ->
return true
expect(.messages().join(' ')).to.match(/Downtime cancelled/)
it 'message does not contain downtime cancelled string if it is not a downtime cancelled icinga notification', ->
expect(.messages().join(' ')).to.not.match(/Downtime cancelled/)