nagios

Date

This week I spent some time configuring nagios to track our infrastructure, including web services and hardware.

Nagios is an interesting piece of software. It’s very flexible and kinda easy to setup. I’ve to say that the documentation is not particularly well written. However sites like http://www.nagiosexchange.org/ make like very easy. Setting it up on debian is pretty straightforward.

It took me a while to understand how the various configuration files are organized and what is the object hierarchy. My small contribution today is about this plugin to check if a web service is up and running.

you can put this snippet in /etc/nagios-plugins/config/url.cfg

define command{
        command_name    check_url
        command_line    /usr/lib/nagios/plugins/check_http -H $HOSTADDRESS$ -I $HOSTADDRESS$ -u $ARG1$
}

define command{
        command_name    check_url_ssl
        command_line    /usr/lib/nagios/plugins/check_http -H $HOSTADDRESS$ --ssl -u $ARG1$
}

Then to use it, you have to add a file (eg. web_services.conf) in /etc/nagios2/conf.d with this content:

define service {
        host_name                       WebService
        service_description             PYTHON
        check_command                   check_url_ssl!https://trac.cduce.org/
        use                             generic-service
        notification_interval           0
}

to check if a particular service is there. The trick is to define a host named WebService to organize all service under one heading.

Next Step is to integrate munin with nagios.


Recursive subtyping revealed

The other day I read the article: “Recursive Subtyping revealed”. A Functional Pearl by Gapeyev, Levin and Pierce. This is a bit of code I wrote to convince myself of the algorithm described in the paper.

You can get the article here

type at =
    |Top |Nat |Bool |Even | Odd
    |Times of ( at * at )
    |Arrow of ( at * at )
    |Mu of ( string * at )
    |Var of string

module S = SortedList.Make(
    struct
        type t = (at * at)
        let compare = compare
        let hash = Hashtbl.hash
        let equal (t1,t2) (s1,s2)  =
          ((compare t1 s1) = 0) && ((compare t2 s2) = 0)
    end
    )

module B = SortedList.Make(
    struct
        type t = string
        let compare = compare
        let hash = Hashtbl.hash
        let equal t s  = (compare t s) = 0
    end
    )

(* canonical substitution *)
let rec sub x t = function
    |Var s when s = x -> t
    |Times(t1,t2) -> Times(sub x t t1,sub x t t2)
    |Arrow(t1,t2) -> Arrow(sub x t t1,sub x t t2)
    |_ as t -> t

(* free variables *)
let rec fv = function
    |Var t -> B.add t B.empty
    |Times(t1,t2) -> B.cup (fv t1) (fv t2)
    |Arrow(t1,t2) -> B.cup (fv t1) (fv t2)
    |_ -> B.empty

exception Undef of (at * at)

let rec subtype (a,s,t) =
    if s = t then S.add (s,t) a
    else if List.mem (s,t) a then a
    else
        let a0 = S.add (s,t) a in
        match (s,t) with
        |_,Top -> a0
        |Mu(x,s1),_ ->
                subtype(a0,sub x s s1,t)
        |_,Mu(x,t1) ->
                subtype(a0,s,sub x t t1)
        |Times(s1,s2),Times(t1,t2) ->
                let a1 = subtype(a0,s1,t1) in
                subtype(a1,s2,t2)
        |Arrow(s1,s2),Arrow(t1,t2) ->
                let a1 = subtype(a0,t1,s1) in
                subtype(a1,s2,t2)
        |_ -> raise (Undef (s,t))

let (<:) t s = subtype([],t,s);;

(* ------------- parser -------------------*)
open Camlp4.PreCast
module TypeGram = MakeGram(Lexer)

let expression = TypeGram.Entry.mk "expression"

EXTEND TypeGram
  GLOBAL: expression;

  expression: [
      "arrow" [ e1 = SELF; "->"; e2 = SELF -> Arrow(e1, e2) ]
    | "prod"  [ e1 = SELF; "x";  e2 = SELF -> Times(e1, e2) ]
    | "var" [
          "Nat" -> Nat
        | "Even" -> Even
        | "Odd" -> Odd
        | "Bool" -> Bool
        | "T" -> Top
        | "mu"; `UIDENT x ; "." ; e = SELF -> Mu(x,e)
        | `UIDENT x -> Var x
        | "("; e = SELF; ")" -> e
    ]
  ];

END

let p s = TypeGram.parse_string expression (Loc.mk "<string>") s
(* ------------- parser -------------------*)

(* Examples *)
let a = p "mu X . ( Nat -> (Nat x X))" ;;
let b = p "Nat -> (Nat x (mu X . (Nat -> (Nat x X))))" ;;

let d = p "mu X . ( Nat -> (Even x X))" ;;
let e = p "mu X . ( Even -> (Nat x X))" ;;

(* suppose Even is subtype of Nat *)
let (<::) t s = subtype([Even,Nat],t,s);;
d <:: e;;

mysql + ssl and xen headahe

Date Tags xen

Well today I tried to understand why our production server (shame shame) has rebooted twice in a row in the last 3 days. The only visible problem in the logs is the infamous xen error : ” xen_net: Memory squeeze in netback driver.” . Googling around it seems kinda common and the recommended solution is to add dom0-min-mem to xend.conf and dom0_mem as a kernel option. I’ve done that and updated the xen hypervisor to the latest bakcported version. The machine is up and running and everything seems fine at the moment. I didn’t touch the kernel. This is an other avenue that I might explore if what I’ve done today didn’t fix the problem.

The second problem today was related to mysql. I wanted to configure it to use SSL. Configuring mysql and the client is not too difficult. And this is working just fine. On the other hand I haven’t manage to convince php5 to connect via ssl. Googleing around didn’t help much.

By default mysql allows non encrypted connections. To force the connection to use SSL, you must specify it per user basis with REQUIRE SSL in a grant statement.


magacli, openipmi, ipmitool

Date

If you manage a dell poweredge, it will come a time where you are curious to know about the health of your machine. These are few notes.

The first thing you will try is probably the dell management server. It’s the usual java monster with web interface and all in it. I don’t like it. So I installed openimpi and got the megacli bianry from the lsi website.

openimpi is easy: apt-get install opemimpi impitools

Then we need to load the impi kernel modules:

ipmi_si
ipmi_devintf
ipmi_msghandler
ipmi_poweroff
ipmi_watchdog

more info about impi on debian can be found here.

The next thing is to get the LSI raid monitoring tool. This is a compendium for this tool. This utility is not packaged for debian and actually is a 32 bits binary. You can download it from here. Then you just need to extract the binary with unzip and rpm.

If you really want to use omsa this page gives you all the info you need.

Monitoring Script

From HERE.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
CONT="a0"
STATUS=0
MEGACLI=/root/bin/megacli

echo -n "Checking RAID status on "
hostname
for a in $CONT
 do

   NAME=`$MEGACLI -AdpAllInfo -$a |grep "Product Name" | cut -d: -f2`
   echo "Controller $a: $NAME"
   noonline=`$MEGACLI PDList -$a | grep Online | wc -l`
   echo "No of Physical disks online : $noonline"
   DEGRADED=`$MEGACLI -AdpAllInfo -a0  |grep "Degrade"`
   echo $DEGRADED
   NUM_DEGRADED=`echo $DEGRADED |cut -d" " -f3`
   [ "$NUM_DEGRADED" -ne 0 ] && STATUS=1
   FAILED=`$MEGACLI -AdpAllInfo -a0  |grep "Failed Disks"`
   echo $FAILED
   NUM_FAILED=`echo $FAILED |cut -d" " -f4`
   [ "$NUM_FAILED" -ne 0 ] && STATUS=1

 done

exit $STATUS

Open source RAID card monitor

http://megactl.svn.sourceforge.net/viewvc/megactl/trunk/

It would be nice to have a munin plugin for this monitoring tools.


ocamlbuild + camlp4 + ocamlfind

Date Tags ocaml

Recently I tried to answer to a problem posed on the OCaml mailing list. Basically the problem is how to compile using ocamlbuild using ocamlfind and camlp4. The Camlp4 wiki has already all the ingredients. Here I mix them up in a short example.

_tags : is the ocamlbuild dep file

bar.ml : is a ml file that uses the syntax extension pa_float to

compile.

foo.ml : is a ml file that depends on bar.ml and the str module

(fetched via ocamlfind)

pa_float.ml : is the source code of the camlp4 syntax extension.

The code

_tags

"pa_float.ml": use_camlp4, pp(camlp4of)
"bar.ml": camlp4o, use_float

bar.ml

let x = Float.( 3/2 - sqrt (1/3) )
let f x =
  Float.(
    let pi = acos(-1) in
    x/(2*pi) - x**(2/3)
  )

foo.ml

open Str
let x = Bar.x

myocamlbuild.ml

open Ocamlbuild_plugin;;
open Command;;

let packages = "str";;

let ocamlfind x = S[A"ocamlfind"; x; A"-package"; A packages];;

dispatch begin function
| Before_options ->
    Options.ocamlc := ocamlfind& A"ocamlc";
    Options.ocamlopt := ocamlfind& A"ocamlopt";

| After_rules ->
    flag ["ocaml"; "pp"; "use_float"] (A"pa_float.cmo");
    flag ["ocaml"; "link"] (A"-linkpkg");
    dep  ["ocaml"; "ocamldep"; "use_float"] ["pa_float.cmo"];
| _ -> ()
end;;

pa_float.ml

module Id = struct
  let name = "pa_float"
  let version = "1.0"
end

open Camlp4

module Make (Syntax : Sig.Camlp4Syntax) = struct
  open Sig
  include Syntax

  class float_subst _loc = object
    inherit Ast.map as super
    method _Loc_t _ = _loc
    method expr =
      function
      | <:expr< ( + ) >> -> <:expr< ( +. ) >>
      | <:expr< ( - ) >> -> <:expr< ( -. ) >>
      | <:expr< ( * ) >> -> <:expr< ( *. ) >>
      | <:expr< ( / ) >> -> <:expr< ( /. ) >>
      | <:expr< $int:i$ >> ->
        let f = float(int_of_string i) in <:expr< $`flo:f$ >>
      | e -> super#expr e
  end;;

  EXTEND Gram
    GLOBAL: expr;

    expr: LEVEL "simple"
    [ [ "Float"; "."; "("; e = SELF; ")" -> (new float_subst _loc)#expr e ]
    ]
    ;
  END
end

let module M = Register.OCamlSyntaxExtension Id Make in ()

To Compile

$ocamlbuild foo.byte -classic-display
/usr/bin/ocamlopt -I /usr/lib/ocaml/3.10.0/ocamlbuild unix.cmxa /usr/lib/ocaml/3.10.0/ocamlbuild/ocamlbuildlib.cmxa myocamlbuild.ml
+/usr/lib/ocaml/3.10.0/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
/usr/bin/ocamldep -modules foo.ml > foo.ml.depends
/usr/bin/ocamldep -pp camlp4of -modules pa_float.ml > pa_float.ml.depends
ocamlfind ocamlc -package str -c -I +camlp4 -pp camlp4of -o pa_float.cmo pa_float.ml
/usr/bin/ocamldep -pp 'camlp4o pa_float.cmo' -modules bar.ml > bar.ml.depends
ocamlfind ocamlc -package str -c -pp 'camlp4o pa_float.cmo' -o bar.cmo bar.ml
ocamlfind ocamlc -package str -c -o foo.cmo foo.ml
ocamlfind ocamlc -package str -linkpkg bar.cmo foo.cmo -o foo.byte