summaryrefslogtreecommitdiff
path: root/roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2
blob: 7b81328fdeadca3a469e1a370a5933a2754e526d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

require('func.php');

        $data = shell_exec("grep -e 'lease [[:digit:]\.]\+ {' -e '\s\+ends' /var/lib/dhcp/dhcpd.leases");

        preg_match_all('/lease ([\d\.]+) \{\n\s+ends \d+ (\d{4}\/\d{2}\/\d{2} \d+:\d{2}:\d{2});/s', $data, $match);

        unset($data, $match[0]);

        $dend = time()-120;

        $clients = 0;

        foreach($match[2] as $timeout) {
                $end = strtotime($timeout.' UTC');
                if($end > $dend) $clients++;
        }

        $data = 'clients,host={{ ansible_hostname }},type=backend value='.$clients;
        sendflux($data);

?>