forked from phpLicenseWatcher/phpLicenseWatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
232 lines (176 loc) · 7.23 KB
/
index.php
File metadata and controls
232 lines (176 loc) · 7.23 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
require_once("common.php");
require_once("tools.php");
print_header("License Server Status");
?>
<link rel="top" href="index.php"/>
</head>
<body>
<h1>License Server Status</h1>
<hr/>
<h2>Flexlm Servers</h2>
<p>To get current usage for an individual server please click on the "Details" link next to the server. If you would like to get current usage for multiple servers on the same page use checkbox on the right of the server then click on the "Get current usage for multiple servers on one page".</p>
<?php
##########################################################################
# We are using PHP Pear library to create tables :-)
##########################################################################
require_once ("HTML/Table.php");
$tableStyle = "class='table' ";
# Create a new table object
$table = new HTML_Table($tableStyle);
//$table->setColAttributes(1,"align=\"center\"");
# Define a table header
$headerStyle = "";
$colHeaders = array("License port@server","Description", "Status", "Current Usage", "Available features/license","Master", "lmgrd version");
$table->addRow($colHeaders, $headerStyle, "TH");
for ( $i = 0 ; $i < sizeof($servers) ; $i++ ) {
$data = run_command($lmutil_loc . " lmstat -c " . $servers[$i]);
$status_string = "";
$detaillink="<a href=\"details.php?listing=0&server=" . $i . "\">Details</a>" ;
$listingexpirationlink="<a href=\"details.php?listing=1&server=" . $i . "\">Listing/Expiration dates</a>" ;
foreach(explode(PHP_EOL, $data) as $line){
/* Look for an expression like this ie. kalahari: license server UP (MASTER) v6.1 */
if ( preg_match ("/: license server UP \(MASTER\)/i", $line) ) {
$status_string = "UP";
$class = "up";
$lmgrdversion = preg_replace("/.*license server UP \(MASTER\)/i ", "", $line);
$lmmaster = substr($line,0,strpos($line,':',0));
}else{
if ( preg_match ("/: license server UP/i", $line) ) {
$status_string = "UP";
$class = "up";
$lmgrdversion = preg_replace("/.*license server UP/i ", "", $line);
$lmmaster = substr($line,0,strpos($line,':',0));
}
}
if ( preg_match ("/Cannot connect to license server/i", $line, $out) ) {
$status_string = "DOWN";
$class = "down";
$lmgrdversion = "" ;
$lmmaster = "";
$detaillink="No details";
$listingexpirationlink="";
break;
}
if ( preg_match ("/Cannot read data/i", $line, $out) ) {
$status_string = "DOWN";
$class = "down";
$lmgrdversion = "" ;
$lmmaster = "";
$detaillink="No details";
$listingexpirationlink="";
break;
}
if ( preg_match ("/Error getting status/i", $line, $out) ) {
$status_string = "DOWN";
$class = "down";
$lmgrdversion = "" ;
$lmmaster = "";
$detaillink="No details";
$listingexpirationlink="";
break;
}
/* Checking if vendor daemon has died evenif lmgrd is still running */
if ( preg_match ("/vendor daemon is down/i", $line, $out) ) {
$status_string = "VENDOR DOWN";
$class = "warning";
$lmgrdversion = preg_replace(".*license server UP \(MASTER\) /i", "", $line);
$lmmaster = substr($line,0,strpos($line,':',0));
preg_replace(".*license server UP /i", "", $line);
break;
}
}
/* If I don't get explicit reason that the server is UP set the status to DOWN */
if ( $status_string == "" ) {
$status_string = "DOWN";
$class = "down";
$lmgrdversion = "" ;
$lmmaster = "";
$detaillink="No details";
$listingexpirationlink="";
}
$table->AddRow(array($servers[$i],$description[$i],$status_string,
$detaillink,
$listingexpirationlink,
$lmmaster,
$lmgrdversion));
# Set the background color of status cell
$table->updateCellAttributes( ($table->getRowCount() - 1) , 3, "class='" . $class . "'");
//$table->updateCellAttributes( 1 , 0, "");
# Close the pipe
//pclose($fp);
}
# Display the table
$table->display();
?>
<?php
# Check whether we are monitoring LUM servers.
if ( isset ($i4blt_loc) && $i4blt_loc != "" ) {
echo ("<h2>LUM Servers</h2>");
$tableStyle = "border=\"1\" cellpadding=\"1\" cellspacing=\"2\" ";
# Create a new table object
$table = new HTML_Table($tableStyle);
$table->setColAttributes(1,"align=\"center\"");
# Define a table header
$headerStyle = "";
$colHeaders = array("Server Name","Target ID", "Target Type", "Server Type", "Details","Status");
$table->addRow($colHeaders, $headerStyle, "TH");
$fp = popen("TIMEOUT_FACTOR=2 ; export TIMEOUT_FACTOR ; " . $i4blt_loc . " -ls ", "r"); // FIXME: shell dependent code!
while ( !feof ($fp) ) {
$line = fgets ($fp, 1024);
# If no license server is running, lum outputs:
# ADM-10037: There are no active license servers
if ( preg_match ("/ADM-10037: There are no active license servers/i", $line) ) {
$servername = "" ;
$targetid = "" ;
$targettype = "" ;
$servertype = "" ;
$details = "" ;
$status_string = "DOWN";
$class="down" ;
$table->AddRow(array($servername,$targetid,$targettype,$servertype, $details, $status_string));
# Set the background color of status cell
$table->updateCellAttributes( ($table->getRowCount() - 1) , 5, "class='" . $class . "'");
$table->updateCellAttributes( 1 , 0, "");
}
# If a license server is running, lum outputs something like:
// ===========================================================================
// === S e r v e r s ===
// ===========================================================================
//
// Server Name: ip:linux.site
// Target ID: 608cf8f8
// Target Type: Linux
// Server Type: Network
// Load: Null or Not Available
// Load Threshold: 90
// Trace: none
//
// ===========================================================================
//
// ==========================
// === End of Server List ===
// ==========================
if ( preg_match ("/Server Name:/i", $line) ) {
$servername = preg_replace(".*Server Name:\ */i", "", $line);
$targetid = preg_replace(".*Target ID:\ */i", "", fgets ($fp, 1024)); // Next line: TargetID
$targettype = preg_replace(".*Target Type:\ */i", "", fgets ($fp, 1024)); // Next line: TargetType
$servertype = preg_replace(".*Server Type:\ */i", "", fgets ($fp, 1024)); // Next line: ServerType
$load = fgets ($fp, 1024); // Next line: Load (not displayed)
$loadthreshold = fgets ($fp, 1024); // Next line: Load Threshod (not displayed)
$trace = fgets ($fp, 1024); // Next line: Trace (not displayed)
$details = "<a href=\"lumdetails.php?server=" . $servername . "\">Details</a>" ;
$status_string = "UP";
$class="up";
$table->AddRow(array($servername,$targetid,$targettype,$servertype, $details, $status_string));
# Set the background color of status cell
$table->updateCellAttributes( ($table->getRowCount() - 1) , 5, "class='" . $class . "'");
$table->updateCellAttributes( 1 , 0, "");
}
}
pclose($fp);
# Display the table
$table->display();
} // end if (
?>
<?php echo footer(); ?>