     return hostname
   ).filter Boolean
 
+  res.set "Content-Type", "text/json"
+
   if query.all?
     res.send services.map (hostname) -> "#{ protocol }//#{ hostname }"
+
+  else unless services.length
+    # FAILURE! send an alert to opsview.
+    nsca.sendStatus 'Services presence', 2, 'Service loadbalancing failure detected!'
+    # Fail-over to the value hard-coded into the config.
+    res.send "\"#{ KONFIG.client.runtimeOptions.broker.sockJS }\""
+
   else
     i = genericServices.seq++ % services.length
-    res.set "Content-Type", "text/json"
     res.send "\"#{ protocol }//#{ services[i] }\""

      console.error 'Negative service count!'

koding.connect ->
  koding.monitorPresence
    join: (serviceKey) ->
      incService serviceKey, 1

{ argv } = require 'optimist'

koding = require './bongo'

nsca = require 'koding-nsca-wrapper'

parseServiceKey = require 'koding-service-key-parser'

