@@ -40,9 +40,9 @@ class IcingadbimgController extends IcingadbGrafanaController
40
40
protected $ custvarconfig = "grafana_graph_config " ;
41
41
protected $ SSLVerifyPeer = false ;
42
42
protected $ SSLVerifyHost = "0 " ;
43
- protected $ cacheTime ;
43
+ protected $ cacheTime = 300 ;
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,7 +68,9 @@ public function init()
68
68
} else {
69
69
$ this ->timerangeto = strpos ($ this ->timerange ?? '' , '/ ' ) ? 'now- ' . $ this ->timerange ?? '' : "now " ;
70
70
}
71
- $ this ->cacheTime = $ this ->hasParam ('cachetime ' ) ? $ this ->getParam ('cachetime ' ) : 300 ;
71
+
72
+ // Get the cachetime URL parameter and use the default if not present
73
+ $ this ->cacheTime = $ this ->hasParam ('cachetime ' ) ? $ this ->getParam ('cachetime ' ) : $ this ->cacheTime ;
72
74
73
75
/* load global configuration */
74
76
$ this ->myConfig = Config::module ('grafana ' )->getSection ('grafana ' );
@@ -97,7 +99,7 @@ public function init()
97
99
$ this ->height = $ this ->myConfig ->get ('height ' , $ this ->height );
98
100
$ this ->width = $ this ->myConfig ->get ('width ' , $ this ->width );
99
101
$ this ->proxyTimeout = $ this ->myConfig ->get ('proxytimeout ' , $ this ->proxyTimeout );
100
- $ this ->refresh = $ this ->myConfig ->get ('indirectproxyrefresh ' , $ this ->refresh );
102
+ $ this ->enableCache = $ this ->myConfig ->get ('enablecache ' , $ this ->enableCache );
101
103
/**
102
104
* Read the global default timerange
103
105
*/
@@ -214,21 +216,15 @@ public function indexAction()
214
216
}
215
217
216
218
$ 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 ));
219
+ $ result = $ this ->getMyimageHtml ($ serviceName , $ hostName , $ imageHtml );
220
+
221
+ if ($ this ->enableCache === 'yes ' ) {
222
+ header ('Cache-Control: public, max-age= ' . $ this ->cacheTime );
226
223
}
224
+
227
225
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 );
226
+
227
+ if (! $ result ) {
232
228
$ string = wordwrap ($ this ->translate ('Error ' ). ': ' . $ imageHtml , 40 , "\n" );
233
229
$ lines = explode ("\n" , $ string );
234
230
$ im = @imagecreate ($ this ->width , $ this ->height );
@@ -368,11 +364,11 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
368
364
}
369
365
370
366
curl_setopt_array ($ curl_handle , $ curl_opts );
371
- $ res = curl_exec ($ curl_handle );
367
+ $ result = curl_exec ($ curl_handle );
372
368
373
369
$ statusCode = curl_getinfo ($ curl_handle , CURLINFO_HTTP_CODE );
374
370
375
- if ($ res === false ) {
371
+ if ($ result === false ) {
376
372
$ imageHtml .=$ this ->translate ('Cannot fetch graph with curl ' ) .': ' . curl_error ($ curl_handle ). '. ' ;
377
373
378
374
// Provide a hint for 'Failed to connect to ...: Permission denied'
@@ -383,7 +379,7 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
383
379
}
384
380
385
381
if ($ statusCode > 299 ) {
386
- $ error = @json_decode ($ res );
382
+ $ error = @json_decode ($ result );
387
383
$ imageHtml .= $ this ->translate ('Cannot fetch Grafana graph ' )
388
384
. ": "
389
385
. Util::httpStatusCodeToString ($ statusCode )
@@ -395,7 +391,7 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
395
391
}
396
392
397
393
curl_close ($ curl_handle );
398
- $ imageHtml = $ res ;
394
+ $ imageHtml = $ result ;
399
395
return true ;
400
396
}
401
397
0 commit comments