nagios_910.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # -*- coding: utf-8 -*-
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  11. # implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. Installs and configures Nagios
  16. """
  17. from packstack.installer import basedefs
  18. from packstack.installer import validators
  19. from packstack.installer import processors
  20. from packstack.installer import utils
  21. from packstack.modules.documentation import update_params_usage
  22. from packstack.modules.common import filtered_hosts
  23. # ------------- Nagios Packstack Plugin Initialization --------------
  24. PLUGIN_NAME = "OS-Nagios"
  25. PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue')
  26. def initConfig(controller):
  27. params = [
  28. {"CMD_OPTION": "nagios-passwd",
  29. "PROMPT": "Enter the password for the nagiosadmin user",
  30. "OPTION_LIST": [],
  31. "VALIDATORS": [validators.validate_not_empty],
  32. "PROCESSORS": [processors.process_password],
  33. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  34. "MASK_INPUT": True,
  35. "LOOSE_VALIDATION": True,
  36. "CONF_NAME": "CONFIG_NAGIOS_PW",
  37. "USE_DEFAULT": False,
  38. "NEED_CONFIRM": False,
  39. "CONDITION": False},
  40. ]
  41. update_params_usage(basedefs.PACKSTACK_DOC, params, sectioned=False)
  42. group = {"GROUP_NAME": "NAGIOS",
  43. "DESCRIPTION": "Nagios Config parameters",
  44. "PRE_CONDITION": "CONFIG_NAGIOS_INSTALL",
  45. "PRE_CONDITION_MATCH": "y",
  46. "POST_CONDITION": False,
  47. "POST_CONDITION_MATCH": True}
  48. controller.addGroup(group, params)
  49. def initSequences(controller):
  50. if controller.CONF['CONFIG_NAGIOS_INSTALL'] != 'y':
  51. return
  52. nagiossteps = [
  53. {'title': 'Preparing Nagios server entries',
  54. 'functions': [create_manifest]},
  55. {'title': 'Preparing Nagios host entries',
  56. 'functions': [create_nrpe_manifests]}
  57. ]
  58. controller.addSequence("Installing Nagios", [], [], nagiossteps)
  59. # -------------------------- step functions --------------------------
  60. def create_manifest(config, messages):
  61. config['CONFIG_NAGIOS_NODES'] = list(filtered_hosts(config))
  62. openstack_services = []
  63. openstack_services.append('keystone-user-list')
  64. if config['CONFIG_GLANCE_INSTALL'] == 'y':
  65. openstack_services.append('glance-index')
  66. if config['CONFIG_NOVA_INSTALL'] == 'y':
  67. openstack_services.append('nova-list')
  68. if config['CONFIG_CINDER_INSTALL'] == 'y':
  69. openstack_services.append('cinder-list')
  70. if config['CONFIG_SWIFT_INSTALL'] == 'y':
  71. openstack_services.append('swift-list')
  72. config['CONFIG_NAGIOS_SERVICES'] = openstack_services
  73. def create_nrpe_manifests(config, messages):
  74. for hostname in filtered_hosts(config):
  75. config['CONFIG_NRPE_HOST'] = hostname
  76. # Only the Nagios host is allowed to talk to nrpe
  77. fw_details = dict()
  78. key = "nagios_nrpe"
  79. fw_details.setdefault(key, {})
  80. fw_details[key]['host'] = "%s" % config['CONFIG_CONTROLLER_HOST']
  81. fw_details[key]['service_name'] = "nagios-nrpe"
  82. fw_details[key]['chain'] = "INPUT"
  83. fw_details[key]['ports'] = ['5666']
  84. fw_details[key]['proto'] = "tcp"
  85. config['FIREWALL_NAGIOS_NRPE_RULES'] = fw_details
  86. messages.append("To use Nagios, browse to "
  87. "http://%(CONFIG_CONTROLLER_HOST)s/nagios "
  88. "username: nagiosadmin, password: %(CONFIG_NAGIOS_PW)s"
  89. % config)