bosun

Bosun: Lookup is giving integer when string is expected


I'm tweaking my bosun.conf to allow my os.cpu.high alert to use a lookup when determining which duration to to use depending on the host:

lookup high_cpu {

    entry host=* {
        time = 5m
    }
    entry host=*graylog* {
        time = 1h
    }
}

alert os.cpu.high {
    template = generic.graph
    macro = host.based.contacts
    $notes = Find CPU usage that is continually high
    $duration = lookup("high_cpu", "time")
    $host = *
    $metric = "sum:rate{counter,,1}:os.cpu{host=$host}"
    $q_cpu = q($metric, "$duration", "")
    $q = avg($q_cpu)

    warn = $q > 95
    crit = $q > 99

    ignoreUnknown = true
    $q_format = %f
    $unit_string = %
    $generic_graph = $q_cpu
    $graph_unit = %
}

This is the error I get when testing:

conf: Test Config:424:4: at <warn = $q > 95>: expr: unexpected "high" in func

I am not very familiar with bosun and this is probably an easy fix, but I'm at my wit's end. Any help would be appreciated


Solution

  • You can't do this, as lookups don't support a string return type.

    This particular scenario would be problematic anyways since what you are trying to do is query different amount of times based on the result of the query, so you have a chicken and egg problem.

    What you can do is query the max amount of time you want to query and then shorten some results in the set using the crop function. However the crop function is not in a release yet so you would have to get it in master. You can see the documentation with an example of what you are trying to do in this commit for now, i.e.:

    lookup test {
        entry host=ny-bosun01 {
            start = 30
        }
        entry host=* {
            start = 60
        }
    }
    
    alert test {
        template = test
        $q = q("avg:rate:os.cpu{host=ny-bosun*}", "5m", "")
        $c = crop($q, lookup("test", "start") , 0)
        crit = avg($c)
    }