problem with "false" in JSON output

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
User avatar
jssingh
Posts: 110
Joined: Mon Apr 29, 2013 4:55 pm

problem with "false" in JSON output

Post by jssingh »

Hi,

there is either a problem with the API JSON output for "false" or an issue with the decoder (I'm using the Perl library "JSON qw( decode_json )"). I noticed it today for one particular query and then checked another query with an output of "false" and the same issue exists.

Here is what it looks like if I just print out the JSON:

Code: Select all

$VAR1 = '{
  "format_version": 0,
  "result": {
    "query_time": 1398720372000,
    "cgi": "statusjson.cgi",
    "query": "downtimelist",
    "query_status": "beta",
    "program_start": 1398360977000,
    "last_data_update": 1398720367000,
    "type_code": 0,
    "type_text": "Success",
    "message": ""
  },
  "data": {
    "selectors": {
    },
    "downtimelist": {
      "4": {
        "downtime_id": 4,
        "type": "host",
        "host_name": "delta",
        "entry_time": 1398720121000,
        "start_time": 1398720094000,
        "flex_downtime_start": 0,
        "end_time": 1398727294000,
        "fixed": false,
        "triggered_by": 0,
        "duration": 7200,
        "is_in_effect": false,
        "start_notification_sent": false,
        "author": "author",
        "comment": "test"
      }
    }
  }
}
';
and this is after I decode it:

Code: Select all

$VAR1 = {
          'format_version' => 0,
          'data' => {
                      'downtimelist' => {
                                          '4' => {
                                                   'is_in_effect' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
                                                   'fixed' => $VAR1->{'data'}{'downtimelist'}{'4'}{'is_in_effect'},
                                                   'downtime_id' => 4,
                                                   'start_time' => '1398720094000',
                                                   'author' => 'author',
                                                   'duration' => 7200,
                                                   'start_notification_sent' => $VAR1->{'data'}{'downtimelist'}{'4'}{'is_in_effect'},
                                                   'end_time' => '1398727294000',
                                                   'comment' => 'test',
                                                   'triggered_by' => 0,
                                                   'flex_downtime_start' => 0,
                                                   'host_name' => 'delta',
                                                   'type' => 'host',
                                                   'entry_time' => '1398720121000'
                                                 }
                                        },
                      'selectors' => {}
                    },
          'result' => {
                        'query' => 'downtimelist',
                        'cgi' => 'statusjson.cgi',
                        'message' => '',
                        'query_status' => 'beta',
                        'program_start' => '1398360977000',
                        'type_text' => 'Success',
                        'type_code' => 0,
                        'query_time' => '1398720372000',
                        'last_data_update' => '1398720367000'
                      }
        };
Has anyone else seen this before? Can this be looked into?

thanks!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: problem with "false" in JSON output

Post by tmcdonald »

Looks like they are ordering the elements differently, and one is using tabs while the other is using spaces. All the data seems to be the same.
Former Nagios employee
User avatar
jssingh
Posts: 110
Joined: Mon Apr 29, 2013 4:55 pm

Re: problem with "false" in JSON output

Post by jssingh »

Hi,

yes, I am aware they are ordered differently, but when the output is false, it decodes weirdly. These are the specific variables:

Code: Select all

'is_in_effect' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )

Code: Select all

'fixed' => $VAR1->{'data'}{'downtimelist'}{'4'}{'is_in_effect'}

Code: Select all

'start_notification_sent' => $VAR1->{'data'}{'downtimelist'}{'4'}{'is_in_effect'}
I would expect them to say:

Code: Select all

'is_in_effect' => false

Code: Select all

'fixed' => false

Code: Select all

'start_notification_sent' => false
(or 0 instead of "false")
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: problem with "false" in JSON output

Post by tmcdonald »

Does the perl library you are using expert a bool false or a string false? I'm not sure why it would output actual code in any case, but it could be a debug message that snuck in there.
Former Nagios employee
User avatar
jssingh
Posts: 110
Joined: Mon Apr 29, 2013 4:55 pm

Re: problem with "false" in JSON output

Post by jssingh »

I'm sorry !! This is a problem with the Data::Dumper library. It's printing out weird stuff instead of true/false. I tried actually using the variable and it worked fine. ;)
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: problem with "false" in JSON output

Post by tmcdonald »

Glad to see it working. Any victory over perl code is a good one. I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee
Locked