/******************************************************************************
 * Icinga 2                                                                   *
 * Copyright (C) 2012-2015 Icinga Development Team (https://www.icinga.org)   *
 *                                                                            *
 * This program is free software; you can redistribute it and/or              *
 * modify it under the terms of the GNU General Public License                *
 * as published by the Free Software Foundation; either version 2             *
 * of the License, or (at your option) any later version.                     *
 *                                                                            *
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with this program; if not, write to the Free Software Foundation     *
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ******************************************************************************/

object CheckCommand "mssql_health" {
	import "plugin-check-command"

	command = [ PluginContribDir + "/check_mssql_health" ]

	arguments = {
		"--hostname" = {
			value = "$mssql_health_hostname$"
			description = "the database server's hostname"
		}
		"--port" = {
			value = "$mssql_health_port$"
			description = "the database's port"
		}
		"--server" = {
			value = "$mssql_health_server$"
			description = "the name of a predefined connection"
		}
		"--currentdb" = {
			value = "$mssql_health_currentdb$"
			description = "the name of a database which is used as the current database for the connection"
		}
		"--username" = {
			value = "$mssql_health_username$"
			description = "the mssql db user"
		}
		"--password" = {
			value = "$mssql_health_password$"
			description = "the mssql db user's password"
		}
		"--warning" = {
			value = "$mssql_health_warning$"
			description = "the warning range"
		}
		"--critical" = {
			value = "$mssql_health_critical$"
			description = "the critical range"
		}
		"--mode" = {
			value = "$mssql_health_mode$"
			description = "the mode of the plugin"
		}
		"--name" = {
			value = "$mssql_health_name$"
			description = "the name of the database etc depending on the mode"
		}
		"--name2" = {
			value = "$mssql_health_name2$"
			description = "if name is a sql statement, name2 can be used to appear in the output and the performance data"
		}
		"--regexp" = {
			set_if = "$mssql_health_regexp$"
			description = "name will be interpreted as a regular expression"
		}
		"--units" = {
			value = "$mssql_health_units$"
			description = "This is used for a better output of mode=sql and for specifying thresholds for mode=tablespace-free"
		}
		"--offlineok" = {
			set_if = "$mssql_health_offlineok$"
			description = "if offline databases are perfectly ok for you"
		}
		"--commit" = {
			set_if = "$mssql_health_commit$"
			description = "turns on autocommit for the dbd::sybase module"
		}
	}

	vars.mssql_health_regexp = false
	vars.mssql_health_offlineok = false
	vars.mssql_health_commit = false
}

object CheckCommand "mysql_health" {
	import "plugin-check-command"
	import "ipv4-or-ipv6"

	command = [ PluginContribDir + "/check_mysql_health" ]

	arguments = {
		"--hostname" = {
			value = "$mysql_health_hostname$"
			description = "the database server's hostname"
		}
		"--port" = {
			value = "$mysql_health_port$"
			description = "the database's port"
		}
		"--socket" = {
			value = "$mysql_health_socket$"
			description = "the database's unix socket"
		}
		"--username" = {
			value = "$mysql_health_username$"
			description = "the mysql db user"
		}
		"--password" = {
			value = "$mysql_health_password$"
			description = "the mysql db user's password"
		}
		"--database" = {
			value = "$mysql_health_database$"
			description = "the database's name"
		}
		"--warning" = {
			value = "$mysql_health_warning$"
			description = "the warning range"
		}
		"--critical" = {
			value = "$mysql_health_critical$"
			description = "the critical range"
		}
		"--mode" = {
			value = "$mysql_health_mode$"
			description = "the mode of the plugin"
		}
		"--name" = {
			value = "$mysql_health_name$"
			description = "currently only used for sql statements"
		}
		"--name2" = {
			value = "$mysql_health_name2$"
			description = "if name is a sql statement, name2 can be used to appear in the output and the performance data"
		}
		"--units" = {
			value = "$mysql_health_units$"
			description = "This is used for a better output of mode=sql and for specifying thresholds for mode=tablespace-free"
		}
		"--labelformat" = {
			value = "$mysql_health_labelformat$"
			description = "one of pnp4nagios (which is the default) or groundwork"
		}
	}

	vars.mysql_health_hostname = "$check_address$"
}

object CheckCommand "oracle_health" {
	import "plugin-check-command"

	command = [ PluginContribDir + "/check_oracle_health" ]

	arguments = {
		"--connect" = {
			value = "$oracle_health_connect$"
			description = "the connect string"
		}
		"--username" = {
			value = "$oracle_health_username$"
			description = "the oracle user"
		}
		"--password" = {
			value = "$oracle_health_password$"
			description = "the oracle user's password"
		}
		"--warning" = {
			value = "$oracle_health_warning$"
			description = "the warning range"
		}
		"--critical" = {
			value = "$oracle_health_critical$"
			description = "the critical range"
		}
		"--mode" = {
			value = "$oracle_health_mode$"
			description = "the mode of the plugin"
		}
		"--name" = {
			value = "$oracle_health_name$"
			description = "the name of the tablespace, datafile, wait event, latch, enqueue, or sql statement depending on the mode"
		}
		"--name2" = {
			value = "$oracle_health_name2$"
			description = "if name is a sql statement, name2 can be used to appear in the output and the performance data"
		}
		"--regexp" = {
			set_if = "$oracle_health_regexp$"
			description = "name will be interpreted as a regular expression"
		}
		"--units" = {
			value = "$oracle_health_units$"
			description = "This is used for a better output of mode=sql and for specifying thresholds for mode=tablespace-free"
		}
		"--ident" = {
			set_if = "$oracle_health_ident$"
			description = "outputs instance and database names"
		}
		"--commit" = {
			set_if = "$oracle_health_commit$"
			description = "turns on autocommit for the dbd::oracle module"
		}
		"--noperfdata" = {
			set_if = "$oracle_health_noperfdata$"
			description = "do not output performance data"
		}
	}

	env = {
		"ORACLE_HOME" = "$oracle_home$"
		"TNS_ADMIN" = "$oracle_tns_admin$"
	}

	vars.oracle_health_regexp = false
	vars.oracle_health_ident = false
	vars.oracle_health_commit = false
	vars.oracle_health_noperfdata = false

	vars.oracle_home = "/usr/lib/oracle/11.2/client64/lib"
	vars.oracle_tns_admin = SysconfDir + "/icinga2/plugin-configs"
}

object CheckCommand "postgres" {
	import "plugin-check-command"
	import "ipv4-or-ipv6"

	command = [ PluginContribDir + "/check_postgres.pl" ]

	arguments = {
		"-H" = {
			value = "$postgres_host$"
			set_if = {{ macro("$postgres_unixsocket$") == false }}
			description = "hostname(s) to connect to; defaults to none (Unix socket)"
		}
		"-p" = {
			value = "$postgres_port$"
			description = "port(s) to connect to; defaults to 5432"
		}
		"-db" = {
			value = "$postgres_dbname$"
			description = "database name(s) to connect to; defaults to 'postgres' or 'template1'"
		}
		"-u" = {
			value = "$postgres_dbuser$"
			description = "database user(s) to connect as; defaults to 'postgres'"
		}
		"--dbpass" = {
			value = "$postgres_dbpass$"
			description = "database password(s); use a .pgpass file instead when possible"
		}
		"--dbservice" = {
			value = "$postgres_dbservice$"
			description = "service name to use inside of pg_service.conf"
		}
		"-w" = {
			value = "$postgres_warning$"
			description = "the warning threshold, range depends on the action"
		}
		"-c" = {
			value = "$postgres_critical$"
			description = "the critical threshold, range depends on the action"
		}
		"--include" = {
			value = "$postgres_include$"
			description = "name(s) items to specifically include (e.g. tables), depends on the action"
		}
		"--exclude" = {
			value = "$postgres_exclude$"
			description = "name(s) items to specifically exclude (e.g. tables), depends on the action"
		}
		"--includeuser" = {
			value = "$postgres_includeuser$"
			description = "include objects owned by certain users"
		}
		"--excludeuser" = {
			value = "$postgres_excludeuser$"
			description = "exclude objects owned by certain users"
		}
		"--assume-standby-mode" = {
			set_if = "$postgres_standby$"
			description = "assume that server in continious WAL recovery mode"
		}
		"--assume-prod" = {
			set_if = "$postgres_production$"
			description = "assume that server in production mode"
		}
		"--action" = {
			value = "$postgres_action$"
			description = "determines the test executed"
		}
	}

	vars.postgres_host = "$check_address$"
	vars.postgres_standby = false
	vars.postgres_production = false
	vars.postgres_unixsocket = false
}

object CheckCommand "mongodb" {
	import "plugin-check-command"

	command = [ PluginContribDir + "/check_mongodb.py" ]

	arguments = {
		"-H" = {
			value = "$mongodb_address$"
			description = "The hostname you want to connect to"
		}
		"-P" = {
			value = "$mongodb_port$"
			description = "The port mongodb is runnung on"
		}
		"-u" = {
			value = "$mongodb_user$"
			description = "The username you want to login as"
		}
		"-p" = {
			value = "$mongodb_passwd$"
			description = "The password you want to use for that user"
		}
		"-A" = {
			value = "$mongodb_action$"
			description = "The action you want to take"
		}
		"-c" = {
			value = "$mongodb_collection$"
			description = "Specify the collection to check"
		}
		"-T" = {
			value = "$mongodb_sampletime$"
			description = "Time used to sample number of pages faults"
		}
		"-q" = {
			value = "$mongodb_querytype$"
			description = "The query type to check [query|insert|update|delete|getmore|command] from queries_per_second"
		}
		"--database" = {
			value = "$mongodb_database$"
			description = "Specify the database to check"
		}
		"-D" = {
			set_if = "$mongodb_perfdata$"
			description = "Enable output of Nagios performance data"
		}
		"--max-lag" = {
			set_if = "$mongodb_maxlag$"
			description = "Get max replication lag (for replication_lag action only)"
		}
		"--mapped-memory" = {
			set_if = "$mongodb_mappedmemory$"
			description = "Get mapped memory instead of resident (if resident memory can not be read)"
		}
		"--ssl" = {
			set_if = "$mongodb_ssl$"
			description = "Connect using SSL"
		}
		"--replicaset" = {
			set_if = "$mongodb_replicaset$"
			description = "Connect to replicaset"
		}
		"--all-databases" = {
			set_if = "$mongodb_alldatabases$"
			description = "Check all databases (action database_size)"
		}
		"-C" = {
			value = "$mongodb_critical$"
			description = "The critical threshold we want to set"
		}
		"-W" = {
			value = "$mongodb_warning$"
			description = "The warning threshold we want to set"
		}
	}

	vars.mongodb_perfdata = true
	vars.mongodb_action = "connections"
}

object CheckCommand "elasticsearch" {
	import "plugin-check-command"

	command = [ PluginContribDir + "/check_elasticsearch" ]

	arguments = {
		"--failure-domain" = {
			value = "$elasticsearch_failuredomain$"
			description = "A comma-separated list of ElasticSearch attributes that make up your cluster's failure domain"
		}
		"--host" = {
			value = "$elasticsearch_host$"
			description = "Hostname or network address to probe, defaults to 'localhost'"
		}
		"--master-nodes" = {
			value = "$elasticsearch_masternodes$"
			description = "Issue a warning if the number of master-eligible nodes in the cluster drops below this number. By default, do not monitor the number of nodes in the cluster"
		}
		"--port" = {
			value = "$elasticsearch_port$"
			description = "TCP port to probe, defaults to 9200"
		}
		"--prefix" = {
			value = "$elasticsearch_prefix$"
			description = "Optional prefix for the ElasticSearch API, defaults to ''"
		}
		"--yellow-critical" = {
			value = "TRUE"
			set_if = "$elasticsearch_yellowcritical$"
			description = "Instead of issuing a 'warning' for a yellow cluster state, issue a 'critical' alert"
		}
	}

	vars.elasticsearch_yellowcritical = false
}