| 1 | #!/usr/bin/python |
|---|
| 2 | # |
|---|
| 3 | # Copyright 2011, Pall Sigurdsson <palli@opensource.is> |
|---|
| 4 | # |
|---|
| 5 | # This script is free software: you can redistribute it and/or modify |
|---|
| 6 | # it under the terms of the GNU General Public License as published by |
|---|
| 7 | # the Free Software Foundation, either version 3 of the License, or |
|---|
| 8 | # (at your option) any later version. |
|---|
| 9 | # |
|---|
| 10 | # This script is distributed in the hope that it will be useful, |
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | # GNU General Public License for more details. |
|---|
| 14 | # |
|---|
| 15 | # You should have received a copy of the GNU General Public License |
|---|
| 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | """This module provides an interface to okconfig utilities |
|---|
| 19 | and operations such as adding new hosts to Nagios or adding |
|---|
| 20 | templates to current hosts |
|---|
| 21 | |
|---|
| 22 | Example Usage: |
|---|
| 23 | |
|---|
| 24 | import okconfig |
|---|
| 25 | okconfig.cfg_file="/etc/nagios/nagios.cfg" |
|---|
| 26 | okconfig.addhost("myhost.example.com", group_name="databases", templates=["linux","mysql"]) |
|---|
| 27 | """ |
|---|
| 28 | |
|---|
| 29 | __author__ = "Pall Sigurdsson" |
|---|
| 30 | __copyright__ = "Copyright 2011, Pall Sigurdsson" |
|---|
| 31 | __credits__ = ["Pall Sigurdsson"] |
|---|
| 32 | __license__ = "GPL" |
|---|
| 33 | __version__ = "0.3" |
|---|
| 34 | __maintainer__ = "Pall Sigurdsson" |
|---|
| 35 | __email__ = "palli@opensource.is" |
|---|
| 36 | __status__ = "Development" |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | cfg_file="/etc/nagios/nagios.cfg" |
|---|
| 40 | template_directory="/etc/nagios/okconfig/examples" |
|---|
| 41 | destination_directory="/etc/nagios/okconfig/hosts" |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | def verify(): |
|---|
| 45 | """Checks if okconfig is installed and properly configured. |
|---|
| 46 | |
|---|
| 47 | Returns True/False |
|---|
| 48 | """ |
|---|
| 49 | pass |
|---|
| 50 | |
|---|
| 51 | def addhost(host_name, ipaddress=None, group_name="default", templates=[], use=None, force=False): |
|---|
| 52 | """Adds a new host to Nagios. Returns true if operation is successful. |
|---|
| 53 | |
|---|
| 54 | Args: |
|---|
| 55 | host_name -- Hostname of the host to be added |
|---|
| 56 | ipaddress -- IP Address of the host (if None, it will be looked up in DNS) |
|---|
| 57 | group_name -- Primary host/contactgroup for this host. (if none, use "default") |
|---|
| 58 | templates -- List of template names to be added to this host |
|---|
| 59 | use -- if this host inherits another host (i.e. "windows-server") |
|---|
| 60 | force -- Force operation. Overwrite config files needed. |
|---|
| 61 | |
|---|
| 62 | Examples: |
|---|
| 63 | addhost(host_name="example_host",group="database_servers") |
|---|
| 64 | |
|---|
| 65 | Returns: |
|---|
| 66 | True if operation was successful. |
|---|
| 67 | """ |
|---|
| 68 | pass |
|---|
| 69 | |
|---|
| 70 | def addtemplate(host_name, template_name, force=False): |
|---|
| 71 | """Adds a new template to existing host in Nagios. |
|---|
| 72 | |
|---|
| 73 | Args: |
|---|
| 74 | host_name -- Hostname to add template to (i.e. "host.example.com") |
|---|
| 75 | template_name -- Name of the template to be added (i.e. "mysql") |
|---|
| 76 | force -- Force operation, overwrites configuration if it already exists |
|---|
| 77 | |
|---|
| 78 | Examples: |
|---|
| 79 | addtemplate(host_name="host.example.com", template="mysql") |
|---|
| 80 | |
|---|
| 81 | Returns: |
|---|
| 82 | True if operation is succesful. |
|---|
| 83 | """ |
|---|
| 84 | pass |
|---|
| 85 | |
|---|
| 86 | def addgroup(group_name, alias=None, force=False): |
|---|
| 87 | """ |
|---|
| 88 | Adds a new hostgroup/contactgroup/servicegroup combo to Nagios. |
|---|
| 89 | |
|---|
| 90 | Args: |
|---|
| 91 | group_name -- Name of the group to be added (i.e. "db-servers") |
|---|
| 92 | alias -- Group alias (i.e. "Database Servers") |
|---|
| 93 | force -- Force operation, overwrites configuration if it already exists |
|---|
| 94 | |
|---|
| 95 | Examples: |
|---|
| 96 | addgroup(group_name="db-servers", alias="Database Servers") |
|---|
| 97 | |
|---|
| 98 | Returns: |
|---|
| 99 | True if operation was successful |
|---|
| 100 | """ |
|---|
| 101 | pass |
|---|
| 102 | |
|---|
| 103 | def findhost(host_name): |
|---|
| 104 | """ |
|---|
| 105 | Returns the filename which defines a specied host. Returns None on failure. |
|---|
| 106 | |
|---|
| 107 | Args: |
|---|
| 108 | host_name -- Name of the host to find |
|---|
| 109 | |
|---|
| 110 | Examples: |
|---|
| 111 | >>> print findhost("host.example.com") |
|---|
| 112 | "/etc/okconfig/hosts/default/host.example.com-host.cfg" |
|---|
| 113 | """ |
|---|
| 114 | pass |
|---|
| 115 | |
|---|
| 116 | def get_templates(): |
|---|
| 117 | """ Returns a list of available templates """ |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | return { |
|---|
| 121 | 'windows': { |
|---|
| 122 | 'parents': [], |
|---|
| 123 | 'name': 'Microsoft Windows', |
|---|
| 124 | }, |
|---|
| 125 | 'linux': { |
|---|
| 126 | 'parents': [], |
|---|
| 127 | 'name': 'Linux' |
|---|
| 128 | }, |
|---|
| 129 | 'dnsregistration': { |
|---|
| 130 | 'parents': ['linux', 'windows'], |
|---|
| 131 | 'name': 'DNS Registration' |
|---|
| 132 | }, |
|---|
| 133 | 'mssql': { |
|---|
| 134 | 'parents': ['windows'], |
|---|
| 135 | 'name': 'Microsoft SQL Server', |
|---|
| 136 | }, |
|---|
| 137 | 'exchange': { |
|---|
| 138 | 'parents': ['windows'], |
|---|
| 139 | 'name': 'Microsoft Exchange Server', |
|---|
| 140 | }, |
|---|
| 141 | 'ssh': { |
|---|
| 142 | 'parents': ['linux'], |
|---|
| 143 | 'name': 'Secure Shell Service' |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | def get_hosts(): |
|---|
| 149 | """ Returns a list of available hosts """ |
|---|
| 150 | #return ["host1","host2","host3"] |
|---|
| 151 | pass |
|---|
| 152 | |
|---|
| 153 | def install_nsclient(remote_host, username, password): |
|---|
| 154 | """ Logs into remote (windows) host and installs NSClient. |
|---|
| 155 | |
|---|
| 156 | Args: |
|---|
| 157 | remote_host -- Hostname/IPAddress of remote host |
|---|
| 158 | username -- Name of a user with administrative privileges on the remote host |
|---|
| 159 | password -- Password to use |
|---|
| 160 | |
|---|
| 161 | Returns: |
|---|
| 162 | True if operation was successful. Otherwise False |
|---|
| 163 | """ |
|---|
| 164 | pass |
|---|
| 165 | |
|---|
| 166 | def install_nrpe(remote_host, username, password=None): |
|---|
| 167 | """ Logs into remote (unix) host and install nrpe-client. |
|---|
| 168 | |
|---|
| 169 | Args: |
|---|
| 170 | remote_host -- Hostname/IPAddress of remote host |
|---|
| 171 | username -- Username to use |
|---|
| 172 | password -- Password to use. If None, try to use ssh keys |
|---|
| 173 | |
|---|
| 174 | Returns: |
|---|
| 175 | True if operation was successful. |
|---|
| 176 | """ |
|---|
| 177 | pass |
|---|
| 178 | |
|---|
| 179 | if __name__ == '__main__': |
|---|
| 180 | 'This leaves room for some unit testing while being run from the command line' |
|---|