mclarkson/nagrestconf

Error for single quote in alias

Opened this issue · 10 comments

woulf commented

Hello,
as the title say even tough it is accepted by nagios, and valid in JSON string, i can't use single quote ( ' ) in alias (big problem for french).
I tried escaping it with the "'" form and with the "\u0027" forms with the same result.
I'm always getting an http 400 error so i guess that's on the nagrestconf webserver side that the problem lay?
Any idea how to solve that?
thanks

No work-around for that one I'm afraid. I'll need to add code to make it a url encoded field.
I'll get this into the next release. What OS are you using?

I've got the code in place. It works but just need to test border cases.
Just let me know your OS so I can build for that first.

woulf commented

Hey, thanks for the quick answer!
I'm the guy with docker ^^ but basically that's a debian jessie

Aha :) Hi!
Surprisingly, for me, this now works in the alias field:

Næmon's Nôra Großen Café

Also, nrcq has been updated so it will work too:

$ nrcq http://NAGIOSHOST/rest show/hosts

    name:diskstation
    alias:Næmon's Nôra Großen Café
    ipaddress:127.0.0.1
    template:hsttmpl-local
    hostgroup:ds
    activechecks:on
    servicesets:diskstation nagios
    disable:0
    notes_url:/highcharts/highcharts.html?host=$HOSTNAME$
    action_url:/highcharts/highcharts.html?host=$HOSTNAME$

$ nrcq http://NAGIOSHOST/rest modify/hosts \
    -d "name:diskstation" \
    -d "alias:Nôra's Großen"
SUCCESS

$ nrcq http://NAGIOSHOST/rest show/hosts

    name:diskstation
    alias:Nôra's Großen
    ...

$ nrcq http://10.11.12.10:8888/rest show/hosts --json
[
  {
    "name":"diskstation",
    "alias":"N%C3%B4ra%27s+Gro%C3%9Fen",
    "ipaddress":"127.0.0.1",
    ...

Jessie .deb's are at sourceforge but I've not tried them so backup your configuration using the GUI before upgrading. I tested Centos 6 RPMS, which seemed to work.

Cheers!
Mark

woulf commented

ok got it in my build/test routine and everything is working as expected on nagrestconf side! :)
However i'm getting the results url-encoded trough "rest/show/hosts", instead of classical json way of dealing with it (not url encoded for ascii, \u+utf8 code for special character), nothing i can't deal with but i just want to check that's by design?
thanks! :)

Yep, that's what the fix was, an extra url encoding. Thanks for testing.

woulf commented

Perfect then, i'll do what needed on my app side,
thanks!

woulf commented

Hey there,
just so you know: the same bug happen on delete/hosts , not a big problem since alias isn't mandatory for this.
Do you think the same will happen for host modification? (havn't developped this part yet)

woulf commented

Coded the modification part Quickly: working perfectly!

Thanks for that Woulf. I'll open this again and fix it for show/hosts and delete/hosts. Even though having the alias field for show and delete is unnecessary, I'd still like to be able to reuse an add or modify line and only have to change the 'add' to 'delete' or 'show'.