#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2013:
#    Gabes Jean, j.gabes@shinken-solutions.com
#
# This file is part of Shinken Enterprise, all rights reserved.

import sys
import optparse

from shinkensolutions.localinstall import get_local_daemons, VERSION, WARNING_COLOR, ERROR_COLOR, OK_COLOR, POSSIBLE_DAEMONS, get_local_instances_for_type, ADDITIONNAL_DAEMONS

if __name__ == '__main__':
    parser = optparse.OptionParser("%prog ", version="%prog: " + VERSION, description='This tool is used to know if one daemon should be run, or not')
    
    opts, args = parser.parse_args()
    
    daemons = get_local_daemons()
    
    if len(args) != 1:
        print "ERROR:Print bad usage of this command"
        sys.exit(2)
    daemon_type = args[0]
    
    # Gatherer: always on, only one
    if daemon_type in ADDITIONNAL_DAEMONS:
        print '0'
        sys.exit(0)
    
    if daemon_type not in POSSIBLE_DAEMONS:
        print "Error: no such daemon is possible"
        sys.exit(2)
    
    local_instances = get_local_instances_for_type(daemon_type)
    which_enabled = [k for (k, enabled) in local_instances if enabled]
    which_enabled.sort()
    if 'central' in daemons or len(which_enabled) != 0:
        print " ".join(which_enabled)
        sys.exit(0)
    print "NO"
    sys.exit(1)
