Project

General

Profile

« Previous | Next » 

Revision e1e543c7

Added by Bill Marquette about 17 years ago

Commit work in progress status screen - at least you can get up/down
on your virtual servers now.

View differences:

usr/local/www/status_slbd_vs.php
40 40
$a_vs = &$config['load_balancer']['virtual_server'];
41 41
$a_pool = &$config['load_balancer']['lbpool'];
42 42

  
43
$slbd_logfile = "{$g['varlog_path']}/slbd.log";
44 43

  
45
$nentries = $config['syslog']['nentries'];
46
if (!$nentries)
47
        $nentries = 50;
48 44

  
49
$now = time();
50
$year = date("Y");
45
// # relayctl show summary
46
// Id   Type      Name                      Avlblty Status
47
// 1    redirect  testvs2                           active
48
// 5    table     test2:80                          active (3 hosts up)
49
// 11   host      192.168.1.2               91.55%  up
50
// 10   host      192.168.1.3               100.00% up
51
// 9    host      192.168.1.4               88.73%  up
52
// 3    table     test:80                           active (1 hosts up)
53
// 7    host      192.168.1.2               66.20%  down
54
// 6    host      192.168.1.3               97.18%  up
55
// 0    redirect  testvs                            active
56
// 3    table     test:80                           active (1 hosts up)
57
// 7    host      192.168.1.2               66.20%  down
58
// 6    host      192.168.1.3               97.18%  up
59
// 4    table     testvs-sitedown:80                active (1 hosts up)
60
// 8    host      192.168.1.4               84.51%  up
61
// # relayctl show redirects
62
// Id   Type      Name                      Avlblty Status
63
// 1    redirect  testvs2                           active
64
// 0    redirect  testvs                            active
65
// # relayctl show redirects
66
// Id   Type      Name                      Avlblty Status
67
// 1    redirect  testvs2                           active
68
//            total: 2 sessions
69
//            last: 2/60s 2/h 2/d sessions
70
//            average: 1/60s 0/h 0/d sessions
71
// 0    redirect  testvs                            active
72

  
73
$redirects_a = exec_command_and_return_text_array('/usr/local/sbin/relayctl show redirects');
74
$summary_a = exec_command_and_return_text_array('/usr/local/sbin/relayctl show summary');
75
$rdr_a = parse_redirects($redirects_a);
76
//$server_a = parse_summary($summary_a, parse_redirects($redirects_a));
77

  
78
function parse_redirects($rdr_a) {
79
  $vs = array();
80
  for ($i = 0; isset($rdr_a[$i]); $i++) {
81
    $line = $rdr_a[$i];
82
    if (preg_match("/^[0-9]+/", $line)) {
83
      $regs = array();
84
      if($x = preg_match("/^[0-9]+\s+redirect\s+([0-9a-zA-Z]+)\s+([a-z]+)/", $line, $regs)) {
85
        $vs[$regs[1]] = array();
86
        $vs[$regs[1]]['status'] = $regs[2];
87
      }
88
    }
89
  }
90
  return $vs;
91
}
92

  
93
function parse_summary($summary, $rdrs_a) {
94
  $server_a = array();
95
  return $server_a;
96
}
51 97

  
52 98
$pgtitle = array("Status","Load Balancer","Virtual Server");
53 99
include("head.inc");
......
91 137
			foreach ($a_pool as $vipent) {
92 138
				if ($vipent['name'] == $vsent['pool']) {
93 139
					foreach ((array) $vipent['servers'] as $server) {
94
						PRINT "<tr><td> {$server} </td></tr>";
140
						print "<tr><td> {$server} </td></tr>";
95 141
					}
96 142
				}
97 143
			}
98 144
			?>
99 145
			</table>
100 146
                  </td>
101
                  <td class="listr" >
102
			<table border="0" cellpadding="0" cellspacing="2">
103
                        <?php
104
				$poolfile = "{$g['tmp_path']}/{$vsent['name']}.pool";
105
				if(file_exists("$poolfile")) {
106
					$poolstatus = file_get_contents("$poolfile");
107
				}
108
				foreach ($a_pool as $vipent) {
109
					if ($vipent['name'] == $vsent['pool']) {
110
                                        foreach ((array) $vipent['servers'] as $server) {
111
						$lastchange = "";
112
						$monitorip = $server;
113
						$logstates = return_clog($slbd_logfile, $nentries, true, array("$monitorip", "marking"), "", true);
114
						$logstates = $logstates[0];
115

  
116
						if(stristr($logstates, $monitorip)) {
117
							$date = preg_split("/[ ]+/" , $logstates);
118
							$lastchange = "$date[0] $date[1] $year $date[2]";
119
						}
120
						if(stristr($poolstatus, $monitorip)) {
121
							$online = "Online";
122
							$bgcolor = "lightgreen";
123
							$change = $now - strtotime("$lastchange");
124
							if($change < 300) {
125
								$bgcolor = "khaki";
126
							}
127
						} else {
128
							$online = "Offline";
129
							$bgcolor = "lightcoral";
130
						}
131
						PRINT "<tr><td bgcolor=\"$bgcolor\" > $online </td><td>";
132
						if($lastchange <> "") {
133
							PRINT "Last change $lastchange";
134
						} else {
135
							PRINT "No changes found in logfile";
136
						}
137
						PRINT "</td></tr>";
138
                                        }
139
				}
140
			}
141
                        ?>
142
			</table>
147
                  <?php
148
                  switch ($rdr_a[$vsent['name']]['status']) {
149
                    case 'active':
150
                      $bgcolor = "lightgreen";
151
                      break;
152
                    default:
153
                      $bgcolor = "lightcoral";
154
                  }
155
                  ?>
156
                  <td class="listr" bgcolor="<?=$bgcolor?>">
157
                  <?=$rdr_a[$vsent['name']]['status']?>
143 158
                  </td>
144 159
                  <td class="listbg" >
145 160
				<font color="#FFFFFF"><?=$vipent['desc'];?></font>

Also available in: Unified diff