TrotskyIcepick Posted February 8, 2010 Share Posted February 8, 2010 Hi, I'm not a php programmer so forgive me if this is an easy one. I am using an addon called pnp4nagios to create performance graphs for the Nagios monitoring software. I have downloaded a custom template which will affect the graphs produced for a monitored service and when it is loaded it gives: templates/check_network_load.php [20]: Undefined offset: 1 The php code being loaded is attached. Any advice will be greatly appreciated. Thanks In Advance Andrew [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/191331-undefined-offset-1-in-pnp4nagios-custom-template/ Share on other sites More sharing options...
alexjb Posted February 8, 2010 Share Posted February 8, 2010 Try changing lines 20 and 22 respectively with: $def[$graphcount] .= "DEF:in_bytes=$rrdfile:" . (($key != null && array_key_exists($key, $DS)) ? $DS[$key] : null) . ":AVERAGE " ; and: $def[$graphcount] .= "DEF:out_bytes=$rrdfile:" . (($nextkey != null && array_key_exists($nextkey, $DS)) ? $DS[$nextkey] : null) . ":AVERAGE " ; Link to comment https://forums.phpfreaks.com/topic/191331-undefined-offset-1-in-pnp4nagios-custom-template/#findComment-1008749 Share on other sites More sharing options...
TrotskyIcepick Posted February 8, 2010 Author Share Posted February 8, 2010 Thanks Alex for the quick response. Unfortunately I still get the same error. I can't pretend to understand why but it seems to be the code: $def[$graphcount] that is causing the error. Regards Andrew Link to comment https://forums.phpfreaks.com/topic/191331-undefined-offset-1-in-pnp4nagios-custom-template/#findComment-1008763 Share on other sites More sharing options...
alexjb Posted February 8, 2010 Share Posted February 8, 2010 Oh right, I see the issue. Script seems quite messy, even for a template file. Under: $graphcount=1; Just paste: $def[$graphcount] = ''; Should fix it right up. Link to comment https://forums.phpfreaks.com/topic/191331-undefined-offset-1-in-pnp4nagios-custom-template/#findComment-1008764 Share on other sites More sharing options...
TrotskyIcepick Posted February 8, 2010 Author Share Posted February 8, 2010 Sorry about this, like I said I'm not a programmer and this is somebody elses code. I tried your last suggestion and now get: Undefined offset: 2. So it would appear to have run through 1 iteration of the script OK and fails on the next increment of graphcount. Thanks Andrew Link to comment https://forums.phpfreaks.com/topic/191331-undefined-offset-1-in-pnp4nagios-custom-template/#findComment-1008766 Share on other sites More sharing options...
alexjb Posted February 8, 2010 Share Posted February 8, 2010 Before this line, $def[$graphcount] .= "DEF:in_bytes=$rrdfile: Add: if(array_key_exists($graphcount, $def) == false) $def[$graphcount] = null; Sorry, late and tired Link to comment https://forums.phpfreaks.com/topic/191331-undefined-offset-1-in-pnp4nagios-custom-template/#findComment-1008772 Share on other sites More sharing options...
TrotskyIcepick Posted February 8, 2010 Author Share Posted February 8, 2010 Thanks Alex, that worked a treat (now I'll try reading up on some PHP basics so I know why it works ) Thanks Very Much Andrew Link to comment https://forums.phpfreaks.com/topic/191331-undefined-offset-1-in-pnp4nagios-custom-template/#findComment-1008779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.