ReliabilityController.php
2.19 KB
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
<?php
namespace Swpb\Bundle\CocarBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Swpb\Bundle\CocarBundle\Entity\Reliability;
class ReliabilityController extends Controller
{
private $dir;
/**
* @Route("/reliability", name="cocar_reliability")
* @Template()
*/
public function reabilityAction()
{
$reliability = new Reliability();
$this->dir = $this->get('kernel')->getRootDir() . "/../web/rrd/rly/";
$em = $this->getDoctrine()->getManager();
$circuits = $em->getRepository('CocarBundle:Circuits')->findAll();
foreach($circuits as $cir)
{
$codInterface = $cir->getCodeInterface();
$hostTip = $cir->getIpSerialRouterTip();
$communityTip = $cir->getCommunitySnmpRouterTip();
$snmpPortTip = $cir->getSnmpPortTip();
$com = "snmpget -Ov -t 1 -r 1 -c $communityTip -v 1 $hostTip .1.3.6.1.4.1.9.2.2.1.1.22.$snmpPortTip 2> /dev/null";
$rly = $this->get('cocar_monitor')->snmp(shell_exec($com));
$rly = (!$rly) ? 0 : $rly;
$date = ((int)(date('U')/600))*600;
$reliability->setCodeInterface($codInterface);
$reliability->setDate($date);
$reliability->setRly($rly);
$em->persist($reliability);
$em->flush();
$arqRrd = $this->dir . $codInterface . "_rly.rrd";
if (!file_exists($arqRrd))
$this->createRrdRly($arqRrd);
$this->updateRrdRly($arqRrd, $date, $rly);
}
return new Response();
}
public function createRrdRly($arqRrd)
{
$com = "rrdtool create " . $arqRrd . " --step 600 " .
"DS:rly:GAUGE:1200:0:256 " .
"RRA:AVERAGE:0.5:1:480 " .
"RRA:AVERAGE:0.5:2:510 " .
"RRA:AVERAGE:0.5:9:500 " .
"RRA:AVERAGE:0.5:36:500 " .
"RRA:AVERAGE:0.5:144:370 " .
"RRA:MIN:0.5:1:480 " .
"RRA:MIN:0.5:2:510 " .
"RRA:MIN:0.5:9:500 " .
"RRA:MIN:0.5:36:500 " .
"RRA:MIN:0.5:144:370";
shell_exec($com);
}
public function updateRrdRly($arqRrd, $date, $rly)
{
shell_exec("rrdtool update $arqRrd $date:$rly");
}
}