Statistics
| Branch: | Tag: | Revision:

root / htools / mon-collector.hs @ fd958a3d

History | View | Annotate | Download (1.9 kB)

1 332b1340 Michele Tartara
{-| Main binary for all stand-alone data collectors
2 332b1340 Michele Tartara
3 332b1340 Michele Tartara
-}
4 332b1340 Michele Tartara
5 332b1340 Michele Tartara
{-
6 332b1340 Michele Tartara
7 332b1340 Michele Tartara
Copyright (C) 2012 Google Inc.
8 332b1340 Michele Tartara
9 332b1340 Michele Tartara
This program is free software; you can redistribute it and/or modify
10 332b1340 Michele Tartara
it under the terms of the GNU General Public License as published by
11 332b1340 Michele Tartara
the Free Software Foundation; either version 2 of the License, or
12 332b1340 Michele Tartara
(at your option) any later version.
13 332b1340 Michele Tartara
14 332b1340 Michele Tartara
This program is distributed in the hope that it will be useful, but
15 332b1340 Michele Tartara
WITHOUT ANY WARRANTY; without even the implied warranty of
16 332b1340 Michele Tartara
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 332b1340 Michele Tartara
General Public License for more details.
18 332b1340 Michele Tartara
19 332b1340 Michele Tartara
You should have received a copy of the GNU General Public License
20 332b1340 Michele Tartara
along with this program; if not, write to the Free Software
21 332b1340 Michele Tartara
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 332b1340 Michele Tartara
02110-1301, USA.
23 332b1340 Michele Tartara
24 332b1340 Michele Tartara
-}
25 332b1340 Michele Tartara
26 332b1340 Michele Tartara
module Main (main) where
27 332b1340 Michele Tartara
28 332b1340 Michele Tartara
import Data.Char (toLower)
29 332b1340 Michele Tartara
import System.Environment
30 332b1340 Michele Tartara
import System.IO
31 332b1340 Michele Tartara
32 332b1340 Michele Tartara
import Ganeti.Utils
33 332b1340 Michele Tartara
import Ganeti.HTools.CLI (parseOpts, genericOpts)
34 332b1340 Michele Tartara
import Ganeti.DataCollectors.Program (personalities)
35 332b1340 Michele Tartara
36 332b1340 Michele Tartara
-- | Display usage and exit.
37 332b1340 Michele Tartara
usage :: String -> IO ()
38 332b1340 Michele Tartara
usage name = do
39 332b1340 Michele Tartara
  hPutStrLn stderr $ "Unrecognised personality '" ++ name ++ "'."
40 332b1340 Michele Tartara
  hPutStrLn stderr "This program must be executed specifying one of the \
41 332b1340 Michele Tartara
                    \following names as the first parameter:"
42 332b1340 Michele Tartara
  mapM_ (hPutStrLn stderr . ("  - " ++) . fst) personalities
43 332b1340 Michele Tartara
  exitErr "Please specify the desired role."
44 332b1340 Michele Tartara
45 332b1340 Michele Tartara
main :: IO ()
46 332b1340 Michele Tartara
main = do
47 332b1340 Michele Tartara
  cmd_args <- getArgs
48 332b1340 Michele Tartara
  let binary =
49 332b1340 Michele Tartara
        if null cmd_args
50 332b1340 Michele Tartara
          then ""
51 332b1340 Michele Tartara
          else head cmd_args
52 332b1340 Michele Tartara
      name = map toLower binary
53 332b1340 Michele Tartara
      boolnames = map (\(x, y) -> (x == name, Just y)) personalities
54 332b1340 Michele Tartara
  case select Nothing boolnames of
55 332b1340 Michele Tartara
    Nothing -> usage name
56 332b1340 Michele Tartara
    Just (fn, options, arguments) -> do
57 332b1340 Michele Tartara
         let actual_args = tail cmd_args
58 332b1340 Michele Tartara
         real_options <- options
59 332b1340 Michele Tartara
         (opts, args) <- parseOpts actual_args name (real_options ++
60 332b1340 Michele Tartara
                           genericOpts) arguments
61 332b1340 Michele Tartara
         fn opts args