This file is indexed.

/usr/share/check_mk/checks/haproxy is in check-mk-server 1.2.8p16-1ubuntu0.1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk 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 in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# tails. You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.


# <<<haproxy:sep(44)>>>
# # pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,
# https_t3test.tgic.de,FRONTEND,,,0,0,2000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,0,,,,0,0,0,0,0,0,,0,0,0,,,0,0,0,0,,,,,,,,
# https_t3test.tgic.de,BACKEND,0,0,0,0,200,0,0,0,0,0,,0,0,0,0,UP,0,0,0,,0,363417,0,,1,2,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,0,0,0,0,-1,,,0,0,0,0,
# t3test,t3test,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,363417,0,,1,3,1,,0,,2,0,,0,L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0,

# <<<haproxy:sep(44)>>>
# BLABLABFO,ELEADC05,0,0,0,5,,841,483793,1386127,,0,,0,751,0,0,UP,1,1,0,0,0,38624,0,,1,5,2,,841,,2,0,,4,L4OK,,0,,,,,,,0,,,,90,751,,,,,169,,,0,0,0,3073,
# BLABLABLABLA,FRONTEND,,,0,0,2000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,0,,,,0,0,0,0,0,0,,0,0,0,,,0,0,0,0,,,,,,,,
# LDAP,IP.IP.IP.IP,,,0,32,250,5892,3365040,9470591,0,0,0,,,,,OPEN,,,,,,,,,1,3,1,,,,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,


# from http://www.haproxy.org/download/1.7/doc/management.txt
# 0=frontend, 1=backend, 2=server, 3=socket/listener


def inventory_haproxy_frontend(info):
    for line in info:
        if line[32] == "0":
            yield line[0], None


def check_haproxy_frontend(item, _no_params, info):
    for line in info:
        if line[0] == item:
            now = time.time()
            status = line[17]
            stot = int(line[7])
            session_rate = get_rate("sessions.%s" % item, now, stot)

            infotext = "%s, Session Rate: %.2f/s" % (status, session_rate)
            perfdata = [ ("session_rate", session_rate) ]

            if status == "OPEN":
                state = 0
            else:
                state = 2

            return state, infotext, perfdata


check_info["haproxy.frontend"] = {
    'check_function'      : check_haproxy_frontend,
    'inventory_function'  : inventory_haproxy_frontend,
    'service_description' : 'HAProxy Frontend %s',
    'has_perfdata'        : True,
}


def inventory_haproxy_server(info):
    for line in info:
        if line[32] == "2":
            yield "%s/%s" % (line[0], line[1]), None


def check_haproxy_server(item, _no_params, info):
    for line in info:
        if "%s/%s" % (line[0], line[1]) == item:
            status = line[17]
            uptime = get_age_human_readable(int(line[23]))
            layer_check = line[36]
            active = int(line[19])
            backup = int(line[20])

            if status == "UP" and (active or backup):
                state = 0
            else:
                state = 2

            infotext = "%s since %s, Layer Check: %s" % \
                        (status, uptime, layer_check)
            if active:
                infotext += ", active"
            elif backup:
                infotext += ", backup"
            else:
                infotext += ", neither active nor backup (!!)"
            return state, infotext


check_info["haproxy.server"] = {
    'check_function'      : check_haproxy_server,
    'inventory_function'  : inventory_haproxy_server,
    'service_description' : 'HAProxy Server %s',
}