echo POST http fkr vsergeev _back_slow type cctv_cams action check -H

 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
#echo '{}' | POST 'http://fkr.vsergeev/_back_slow/?type=cctv_cams&action=check' -H 'Content-Type: application/json'
sub do_check_cctv_cams {
my $cctv_cams = sql_select_all('SELECT * FROM cctv_cams WHERE fake = 0 ORDER BY id ASC');
require LWP::Simple;
my $ua = LWP::UserAgent -> new (
default_headers => HTTP::Headers -> new (accept => 'application/json'),
timeout => $cnf -> {seconds},
keep_alive => 1,
);
my $ok = 0;
foreach my $cctv_cam (@$cctv_cams){
my $url = "https://fkr-cams.reginc.pro:1936/live/$cctv_cam->{code}/playlist.m3u8";
eval {
my $r = $ua -> get ($url);
$ok = $r -> status_line == "200 OK" ? 1 : 0;
};
sql_do ('UPDATE cctv_cams SET is_alive = ?, dt_check = now() WHERE id = ?', $ok, $cctv_cam -> {id});
}
}