-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_freifunk_clients
More file actions
executable file
·43 lines (35 loc) · 1018 Bytes
/
check_freifunk_clients
File metadata and controls
executable file
·43 lines (35 loc) · 1018 Bytes
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
#!/usr/bin/perl
# Check the number of connected nodes for a given
# Freifunk Node name
# URL = http://map.ffm.freifunk.net/ffmap-d3/nodes.json
# Returns OK with the number
# Except for technical problems
# Written by Darko Krizic <[email protected]>
use strict;
use warnings;
use LWP::Simple;
use JSON;
use Data::Dumper;
my $url = shift;
my $nodename = shift;
unless ($nodename) {
$url = "" unless defined $url;
$nodename = "" unless defined $nodename;
print "CRITICAL: Wrong parameters (url=$url, nodename=$nodename)\n";
exit 2;
}
my $content = get( $url );
my $json = decode_json( $content );
my @nodes = @{$json->{'nodes'}};
for my $node ( @nodes ) {
my %node = %{$node};
my $name = $node{'name'};
next if $name ne $nodename;
my $clientcount = $node{'clientcount'};
my $firmware = $node{'firmware'};
my $id = $node{'id'};
print "OK: Node '$name' (id $id, firmware $firmware) has $clientcount clients | clientcount=$clientcount\n";
exit 0;
}
print "WARNING: Node '$nodename' not found\n";
exit 1;