-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Package for writing monitoring plugins
--   
--   Implements Nagios plugin development guidelines within a Haskell
--   framework for writing Nagios checks.
@package nagios-check
@version 0.3.2

module System.Nagios.Plugin

-- | Nagios plugin exit statuses. Ordered by priority - <a>OK</a> &lt;
--   <a>Warning</a> &lt; <a>Critical</a> &lt; <a>Unknown</a>, which
--   correspond to plugin exit statuses of 0, 1, 2, and 3 respectively.
data CheckStatus

-- | Check executed successfully and detected no service problems.
OK :: CheckStatus

-- | Nothing's actually broken but this should be followed up.
Warning :: CheckStatus

-- | Check executed successfully and detected a service failure.
Critical :: CheckStatus

-- | Check unable to determine service status.
Unknown :: CheckStatus

-- | A CheckResult is the exit status of the plugin combined with the
--   plugin's info text. A <a>NagiosPlugin</a> which exits with
--   
--   <pre>
--   CheckResult (Critical "entropy decreasing in closed system")
--   </pre>
--   
--   as its peak-badness CheckResult (and no <a>PerfDatum</a>s) will a)
--   exit with status 2 and b) output the text "CRITICAL: entropy
--   decreasing in closed system".
data CheckResult
data NagiosPlugin a

-- | Execute a Nagios check. The program will terminate at the check's
--   completion. A default status will provided if none is given.
runNagiosPlugin :: NagiosPlugin a -> IO ()

-- | Execute a Nagios check as with <a>runNagiosPlugin</a>, but return its
--   final state rather than terminating.
runNagiosPlugin' :: NagiosPlugin a -> IO (a, CheckState)

-- | Insert a performance metric into the list the check will output.
addPerfDatum :: Text -> PerfValue -> UOM -> Maybe PerfValue -> Maybe PerfValue -> Maybe PerfValue -> Maybe PerfValue -> NagiosPlugin ()

-- | Alternative mechanism for adding perfdata generated from complex
--   types; just implement the <a>toPerfData</a> typeclass.
addPerfData :: ToPerfData a => a -> NagiosPlugin ()

-- | Convenience function to insert a perfdatum without thresholds for min,
--   max, warn or crit. Note that unless the range of the metric is
--   actually unbounded, specifying explicit thresholds is considered good
--   practice (it makes life easier for authors of graphing packages).
--   
--   FIXME: implement thresholds properly and default to negative and
--   positive infinity for min and max here.
addBarePerfDatum :: Text -> PerfValue -> UOM -> NagiosPlugin ()

-- | Insert a result. Only the <a>CheckStatus</a> with the most
--   <tt>badness</tt> will determine the check's exit status.
addResult :: CheckStatus -> Text -> NagiosPlugin ()

-- | Extract the return status from a <a>CheckResult</a>.
checkStatus :: CheckResult -> CheckStatus

-- | Extract the infotext from a <a>CheckResult</a>.
checkInfo :: CheckResult -> Text

-- | Returns result with greatest badness, or a default UNKNOWN result if
--   no results have been specified.
worstResult :: [CheckResult] -> CheckResult

-- | Given a check's final state, return the status and output it would
--   exit with.
finishState :: CheckState -> (CheckStatus, Text)

-- | A Nagios "unit of measure". <tt>NoUOM</tt> translates to an empty
--   string in the check output; it is idiomatic to use it liberally
--   whenever the standard units do not fit.
data UOM
Second :: UOM
Millisecond :: UOM
Microsecond :: UOM
Percent :: UOM
Byte :: UOM
Kilobyte :: UOM
Megabyte :: UOM
Gigabyte :: UOM
Terabyte :: UOM
Counter :: UOM
NullUnit :: UOM

-- | <i>Deprecated: Will be removed in 0.4.0 in favour of failing on
--   parse.</i>
UnknownUOM :: UOM

-- | Value of a performance metric.
data PerfValue
RealValue :: Double -> PerfValue
IntegralValue :: Int64 -> PerfValue

-- | One performance metric. A plugin will output zero or more of these,
--   whereupon Nagios generally passes them off to an external system such
--   as <a>RRDTool</a> or <a>Vaultaire</a>. The thresholds are purely
--   informative (designed to be graphed), and do not affect alerting;
--   likewise with <a>_min</a> and <a>_max</a>.
data PerfDatum
PerfDatum :: Text -> PerfValue -> UOM -> Maybe PerfValue -> Maybe PerfValue -> Maybe PerfValue -> Maybe PerfValue -> PerfDatum

-- | Name of quantity being measured.
[_label] :: PerfDatum -> Text

-- | Measured value, integral or real.
[_value] :: PerfDatum -> PerfValue

-- | Unit of measure; <tt>NoUOM</tt> is fine here.
[_uom] :: PerfDatum -> UOM

-- | Measured quantity cannot be lower than this.
[_min] :: PerfDatum -> Maybe PerfValue

-- | Measured quantity cannot be higher than this.
[_max] :: PerfDatum -> Maybe PerfValue

-- | Warning threshold for graphing.
[_warn] :: PerfDatum -> Maybe PerfValue

-- | Critical threshold for graphing.
[_crit] :: PerfDatum -> Maybe PerfValue
class ToPerfData a
toPerfData :: ToPerfData a => a -> [PerfDatum]
toPerfData :: ToPerfData a => a -> [PerfDatum]

-- | Create a PerfDatum from only the required values, using Nothing for
--   all the others.
barePerfDatum :: Text -> PerfValue -> UOM -> PerfDatum
