PHP Error Adding Services to Hosts

Support requests, bug reports, questions etc.
DougWare
PHP Error Adding Services to Hosts

Post by DougWare » Wed Mar 18, 2009 06:33

PHP Warning: in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argument in /usr/share/nagios/nconf/modify_item_service.php on line 102, referer: http://HOSTNAME/nconf/modify_item_service.php?id=5260

I can't add services, the error above is displayed in the logs and the service doesn't show that it's been added.

Doug

User avatar
fgander
NConf developer
NConf developer
Posts:308
Joined:Mon Mar 16, 2009 14:23
Location:Bern, Switzerland
Contact:

Re: PHP Error Adding Services to Hosts

Post by fgander » Wed Mar 18, 2009 11:45

Hi!

Ok, i tried to locate your problem.
The Warning you send me should not be the problem, but i also fixed it for next release. The warning just say there was no services for this host.

So you are in the Services window and try to add with the button ? (like in the attached image)
Are you adding a new host (then it would be step 3) or just modifying the services of a host?
what service do you add? looks the service fine in the Checkcommand ?
when you activate DEBUG_MODE ist there some "FAILED" at the bottom of the page ?

Thx for more infos.
Attachments
modify_item_service.gif
Add service to host
modify_item_service.gif (5.33KiB)Viewed 11334 times
F.G. - NConf developer
http://www.nconf.org
Image
Follow NConf on Twitter!

Tom

Re: PHP Error Adding Services to Hosts

Post by Tom » Mon Mar 30, 2009 00:35

Hello,

I`m new to nconf and I`m receive the following message in debug mode, if I want to add an additional service to an existing host:
"Sorry the submited infos are not allowed to be resent, go to the form and submit it"
What does this message mean to me?

I cannot add any additional service, I`ve tried many of them....

any help is highly welcome,

best regards,

tom

User avatar
fgander
NConf developer
NConf developer
Posts:308
Joined:Mon Mar 16, 2009 14:23
Location:Bern, Switzerland
Contact:

Re: PHP Error Adding Services to Hosts

Post by fgander » Wed Apr 01, 2009 14:34

Hi

NConf has a machanism which will not allow resending a form (a html <form>).
With resending, i mean the "F5" function of a browser, or going back to a form which was already sent.
This must be done, otherwise it could made some wrong actions... (duplicates etc.)
-> NConf will do this with session variables and form elements

Until now, i cannot reproduce your problem...
try logout, login, then go to the hosts-> service , select a service and click the "ADD" button...
-> this really not works ?
look for a message in the Debug panel like this :
The Session counter is : 15 and the the submited counter is 14
is there such a message ? it should only appear, when you press F5 after adding a service...
(perhaps you have a session problem) :?

regards Fäbu
F.G. - NConf developer
http://www.nconf.org
Image
Follow NConf on Twitter!

mpalyga

Re: PHP Error Adding Services to Hosts

Post by mpalyga » Wed Apr 01, 2009 22:55

Hello,
I have the same problem, if I try to add, I receive a info message:

Info:
Sorry the submited infos are not allowed to be resent, go to the form and submit it


But ... if I logout from pannel and log in again, it is possible to add one services and info message listed above is visible instead of adding services to host.

The Debug section looks ok, without any errors messages. Also there is nothing interesing in apache log file :(

Any suggestion ?

regards
m.

User avatar
fgander
NConf developer
NConf developer
Posts:308
Joined:Mon Mar 16, 2009 14:23
Location:Bern, Switzerland
Contact:

Re: PHP Error Adding Services to Hosts

Post by fgander » Thu Apr 02, 2009 01:03

hi.
not good, i have to find the problem, i just cant get it.
give some more informations, what browser on which version are you using?
it looks that your session or submitted form is not working correctly... :? the crazy thing is, i tested it on IE,firefox,chrome etc and it works...
i will have a look tomorrow...
F.G. - NConf developer
http://www.nconf.org
Image
Follow NConf on Twitter!

User avatar
fgander
NConf developer
NConf developer
Posts:308
Joined:Mon Mar 16, 2009 14:23
Location:Bern, Switzerland
Contact:

Re: PHP Error Adding Services to Hosts

Post by fgander » Thu Apr 02, 2009 10:40

Please go to line 53 in the script modify_item_service.php and replace the $debug with $error
try again to add some services...
now you should see a red error message, please send me this, perhaps i can locate the problem better.... :roll:
F.G. - NConf developer
http://www.nconf.org
Image
Follow NConf on Twitter!

Guest

Re: PHP Error Adding Services to Hosts

Post by Guest » Thu Apr 02, 2009 16:46

Hi'
I've tested nconf on various browesers: IE 6, IE 7 (7.0.5730.13), FF 3.0.6, FF 3.0.08 (both linux and windows), Safari 4.0 beta, Opera .. and this is the same issue.

As you wished, I've changed the debug to error and full message below (as last result of "add service"



Info: Sorry the submited infos are not allowed to be resent, go to the form and submit it
Error: The Session counter is : 20 and the the submited counter is 45
Debug:
Select user Navigation classes
* SELECT grouping, nav_links, friendly_name FROM ConfigClasses WHERE nav_privs = "user" AND nav_visible = "yes" ORDER BY UPPER(grouping), ordering ASC, config_class
[ OK ] # Array, rows:3
Select admin Navigation classes
* SELECT * FROM ConfigClasses WHERE nav_privs = "admin" AND nav_visible = "yes" ORDER BY UPPER(grouping), ordering ASC, config_class
[ OK ] # Array, rows:10
regex matched: modify_item_service.php
regex matched: modify_item
url-authorization regex matched :yes
set sourcepage for edit: modify_item_service.php?id=5260
select naming_attr name
* SELECT attr_value FROM ConfigValues, ConfigAttrs WHERE fk_id_attr=id_attr AND naming_attr="yes" AND fk_id_item=5260
[ OK ] # getOne: localhost
SELECT ConfigValues.fk_id_item AS id, attr_value AS entryname FROM ConfigValues, ConfigAttrs, ConfigClasses, ItemLinks WHERE id_attr = ConfigValues.fk_id_attr AND naming_attr = "yes" AND id_class = fk_id_class AND config_class = "service" AND ConfigValues.fk_id_item = ItemLinks.fk_id_item AND fk_item_linked2 = 5260 ORDER BY entryname
var_dump($_POST) :
array(5) {
["HIDDEN_host_ID"]=> string(4) "5260"
["add_checkcommand"]=> string(4) "5248"
["HIDDEN_checkcommands"]=> array(14) {
[5241]=> string(9) "check_ftp"
[5242]=> string(10) "check_hpjd"
[5244]=> string(10) "check_http"
[5248]=> string(10) "check_imap"
[5305]=> string(16) "check_linux_raid"
[5240]=> string(20) "check_local_mrtgtraf"
[5252]=> string(8) "check_nt"
[5246]=> string(10) "check_ping"
[5247]=> string(9) "check_pop"
[5249]=> string(10) "check_smtp"
[5243]=> string(10) "check_snmp"
[5245]=> string(9) "check_ssh"
[5250]=> string(9) "check_tcp"
[5251]=> string(9) "check_udp"
}
["HIDDEN_count"]=> string(2) "45"
["add_service"]=> string(3) "Add"
}

User avatar
fgander
NConf developer
NConf developer
Posts:308
Joined:Mon Mar 16, 2009 14:23
Location:Bern, Switzerland
Contact:

Re: PHP Error Adding Services to Hosts

Post by fgander » Mon Apr 06, 2009 09:57

sorry for that, at the moment i cannot understand what i did wrong...

the counters both should be the same... i do not have any idea why you have 20 and 45 ...

i have to check this in detail...

thank you for your infos, hope to give you soon a fix for that... really crazy thing.. :evil:

hope you will stand by, thx and regards
Fäbu
F.G. - NConf developer
http://www.nconf.org
Image
Follow NConf on Twitter!

mpalyga

Re: PHP Error Adding Services to Hosts

Post by mpalyga » Mon Apr 06, 2009 10:17

Hello,
any news ? any ideas ?

Additionally I've tested nconf on many computer with many version of browsers and issue still exists. I guess that it can be issue assigned to web server configuration and stored session file. I didn't see any interesting error messages in web server log but tonight I'll increase debug level and maybe I'll find something interesting.

btw. is possible to turn on more detailed debug in NCONF ?

cheers
m.

mpalyga

Re: PHP Error Adding Services to Hosts

Post by mpalyga » Mon Apr 06, 2009 10:20

Hello
Ha ... thx Fäbu for answer.. you were much quicker than me in answering :D

as I wrote .. I'll check something tonight and let you you know .. I suppose that the problem is assigned to web server .. but I have to check it

regards
m.

User avatar
fgander
NConf developer
NConf developer
Posts:308
Joined:Mon Mar 16, 2009 14:23
Location:Bern, Switzerland
Contact:

Re: PHP Error Adding Services to Hosts

Post by fgander » Mon Apr 06, 2009 11:27

ok, so i will try to explain what my idea was , and how i implemented that in NConf... :roll:

mainly its a not "must have" mechanism... i just wanted to know, that people cannot resent data with the F5 / resending POST data, so that data may be corrupted in database and also to avoid duplicated entries...

so my idea was, to have a session "counter", an session variable which increases (+1) on every page load.
the code is at the top of the include/head.php:

Code: Select all

session_start();

// no Form-resending when browser refresh with button or F5
if ( isset($_SESSION["count"]) ){
    $_SESSION["count"]++;
}else{
    $_SESSION["count"] = 1;
}
now to have a value which will tell me, if the form was submitting correct, or resend with F5/refresh, i put the counter into an hidden input value:
modify_item_service.php
Row: 122

Code: Select all

<input name="HIDDEN_count" type="hidden" value="<?php echo ($_SESSION["count"] + 1);?>">
:!: important is the + 1, because, when you submit the form, on next page the session will also be increased, so both values should then be the same.

these is checked here:
Row: 21

Code: Select all

$check_count = $_POST["HIDDEN_count"];
Row: 47

Code: Select all

if( $_SESSION["count"] == $check_count){
-> writes data into database
else it will display the error/debug message

This of course will only work when i set the counter in the hidden input increased with one...

example, when i add a service, the session counter is 10, the hidden counter(in the form) should be 11 (increased with one)
so when click on Add, the post data will saved, because the session counter now also is increased with one, and both are 11 (or should be)...

so, when you press F5 you will submit the "old" POST data, the session counter otherwise will be increased with one again, so the session counter now is 12 , and your form submitts 11, this should avoid saving the data to the db...

now, i hope you understand me idea...
Do you have some idea, why this is not working correct at your installation ?
:!: ( to avoid problems, don't use NConf with multi tabs, the session data could work incorrect.. ) could there be an other variable like $_SESSION["count"] which makes NConf problems at your location?

Thanks for your help ;)

any ideas to improve that is welcome... (or just debug) :evil:
F.G. - NConf developer
http://www.nconf.org
Image
Follow NConf on Twitter!

mpalyga

Re: PHP Error Adding Services to Hosts

Post by mpalyga » Thu Apr 09, 2009 10:10

egh ... no time for downtime .... I had no chance to make some test and debug... I hope that during Estern I'll be able to it.

But ... I've made some quick test with refreshing web page and results look like:

Start adding services after first clicking add button (
Error:
The Session counter is : 14 and the the submited counter is 18


I've refreshed web page using F5/reload webpage and submitted counter was decresed, see below
Error:
The Session counter is : 14 and the the submited counter is 16


I guess that is something wrong in mechanism what you describe above ... So, if I'll find free time (during Estern it should be :D) I'll review source file and I'll try to debug them. maybe I'll find something interesting :D

cheers and happy Eastern :D
m.

User avatar
fgander
NConf developer
NConf developer
Posts:308
Joined:Mon Mar 16, 2009 14:23
Location:Bern, Switzerland
Contact:

Re: PHP Error Adding Services to Hosts

Post by fgander » Thu Apr 09, 2009 13:44

this is really crazy... :|

so it seems that the session counter is not getting higher, and the value of the form is also not that one which should be...

crazy stuff, i do not understand why it works correctly on my installation, and on yours its so different... hmm

so, i am very interested where the problem could be... at this moment i do not understand.. :)
i will also try to recheck the whole thing... thx for analyzing this...
:roll:

i am looking on php.net and see same example...

Code: Select all

<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}
?>
it could be a session cookie problem on your system.. or perhaps the session id changes ... hmm more debbing will bring us closer :lol:
F.G. - NConf developer
http://www.nconf.org
Image
Follow NConf on Twitter!

Guest

Re: PHP Error Adding Services to Hosts

Post by Guest » Wed Apr 15, 2009 14:07

I've reviewed the code modify_item_service.php and I've found that the the "hidden session counter" is counted incorrectly. I dont know why but, below error messages, (I've remove line with comparing hidden and session counter and service is added permanently)

add new service
Error: The Session counter is : 15 and the the submited counter is 18
add new service
Error: The Session counter is : 16 and the the submited counter is 43
add new service
Error: The Session counter is : 17 and the the submited counter is 44
paged refreshed by F5 button
Error: The Session counter is : 18 and the the submited counter is 45 (duplicated service check was added to services)
paged refreshed by F5 button
Error: The Session counter is : 19 and the the submited counter is 45
service removed and added again
Error: The Session counter is : 19 and the the submited counter is 53

for first time, during adding the session counter is set 15 and hidde counter to 18 (what is wrong)
next add, session counter is increased by 1 (session counter: 16), and submitted is hidden counter is 43 (what is wrong again)
after next few times, session counter and hidden counter is increased by 1 (corretcly in theory) but after refreshing web page we have:
session counter is 19 and hidden counter 53.

I see that the problem is with counting hidden session counter, I dont know why ... but it looks like:
- hidden session counter is increased more time per session
- or session counter is changed during running session ...

Unfortunately I have no additional time to debug more, but I guess ... I'll do it today evening :D... wish me Good Luck :D

regards
m.

Locked