@@ -42,7 +42,7 @@ class IcingadbimgController extends IcingadbGrafanaController
42
42
protected $ SSLVerifyHost = "0 " ;
43
43
protected $ cacheTime ;
44
44
protected $ defaultdashboarduid ;
45
- protected $ refresh = "yes " ;
45
+ protected $ enableCache = "yes " ;
46
46
protected $ customVars ;
47
47
protected $ timerangeto ;
48
48
protected $ object ;
@@ -68,6 +68,7 @@ public function init()
68
68
} else {
69
69
$ this ->timerangeto = strpos ($ this ->timerange ?? '' , '/ ' ) ? 'now- ' . $ this ->timerange ?? '' : "now " ;
70
70
}
71
+
71
72
$ this ->cacheTime = $ this ->hasParam ('cachetime ' ) ? $ this ->getParam ('cachetime ' ) : 300 ;
72
73
73
74
/* load global configuration */
@@ -97,7 +98,7 @@ public function init()
97
98
$ this ->height = $ this ->myConfig ->get ('height ' , $ this ->height );
98
99
$ this ->width = $ this ->myConfig ->get ('width ' , $ this ->width );
99
100
$ this ->proxyTimeout = $ this ->myConfig ->get ('proxytimeout ' , $ this ->proxyTimeout );
100
- $ this ->refresh = $ this ->myConfig ->get ('indirectproxyrefresh ' , $ this ->refresh );
101
+ $ this ->enableCache = $ this ->myConfig ->get ('enablecache ' , $ this ->enableCache );
101
102
/**
102
103
* Read the global default timerange
103
104
*/
@@ -214,21 +215,15 @@ public function indexAction()
214
215
}
215
216
216
217
$ imageHtml = "" ;
217
- $ res = $ this ->getMyimageHtml ($ serviceName , $ hostName , $ imageHtml );
218
- header ('Pragma: public ' );
219
- if ($ this ->refresh == "yes " ) {
220
- header ('Pragma: public ' );
221
- header ("Expires: " .gmdate ("D, d M Y H:i:s " , time () + $ this ->cacheTime )." GMT " );
222
- header ('Cache-Control: max-age= ' .$ this ->cacheTime ).', public ' ;
223
- } else {
224
- header ("Expires: " .gmdate ("D, d M Y H:i:s " , time () + 365 *86440 )." GMT " );
225
- header ('Cache-Control: max-age= ' . (365 *86440 ));
218
+ $ result = $ this ->getMyimageHtml ($ serviceName , $ hostName , $ imageHtml );
219
+
220
+ if ($ this ->enableCache === 'yes ' ) {
221
+ header ('Cache-Control: public, max-age= ' . $ this ->cacheTime );
226
222
}
223
+
227
224
header ("Content-type: image/png " );
228
- if (! $ res ) {
229
- // set expire to now and max age to 1 minute
230
- header ("Expires: " .gmdate ("D, d M Y H:i:s " , time ())." GMT " );
231
- header ('Cache-Control: max-age= ' . 120 );
225
+
226
+ if (! $ result ) {
232
227
$ string = wordwrap ($ this ->translate ('Error ' ). ': ' . $ imageHtml , 40 , "\n" );
233
228
$ lines = explode ("\n" , $ string );
234
229
$ im = @imagecreate ($ this ->width , $ this ->height );
@@ -368,11 +363,11 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
368
363
}
369
364
370
365
curl_setopt_array ($ curl_handle , $ curl_opts );
371
- $ res = curl_exec ($ curl_handle );
366
+ $ result = curl_exec ($ curl_handle );
372
367
373
368
$ statusCode = curl_getinfo ($ curl_handle , CURLINFO_HTTP_CODE );
374
369
375
- if ($ res === false ) {
370
+ if ($ result === false ) {
376
371
$ imageHtml .=$ this ->translate ('Cannot fetch graph with curl ' ) .': ' . curl_error ($ curl_handle ). '. ' ;
377
372
378
373
//provide a hint for 'Failed to connect to ...: Permission denied'
@@ -383,7 +378,7 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
383
378
}
384
379
385
380
if ($ statusCode > 299 ) {
386
- $ error = @json_decode ($ res );
381
+ $ error = @json_decode ($ result );
387
382
$ imageHtml .= $ this ->translate ('Cannot fetch Grafana graph ' )
388
383
. ": "
389
384
. Util::httpStatusCodeToString ($ statusCode )
@@ -395,7 +390,7 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
395
390
}
396
391
397
392
curl_close ($ curl_handle );
398
- $ imageHtml = $ res ;
393
+ $ imageHtml = $ result ;
399
394
return true ;
400
395
}
401
396
0 commit comments