0

I have JSON data in the following format :

[
{
    "_index": "servers",
    "_id": "server1",
    "_score": 1,
    "_source": {
        "list": {
            "key1": {
                "c1": {
                    "check_status": "PASSED",
                    "check_name": "c1",
                    "error_msg": "NOERRORS",
                    "check_state": "OK"
                },
                "c2": {
                    "check_status": "PASSED",
                    "check_name": "c2",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                }
            },
            "key2": {
                "c11": {
                    "check_status": "PASSED",
                    "check_name": "c11",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                },
                "c22": {
                    "check_status": "PASSED",
                    "check_name": "c22",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                }
            }
        },
        "Date Universal": "2015-10-19T10:14:03Z",
        "SERVER EXISTENCE": "active"
    }
},
{
    "_index": "servers",
    "_id": "server2",
    "_score": 1,
    "_source": {
        "list": {
            "key1": {
                "c1": {
                    "check_status": "PASSED",
                    "check_name": "c1",
                    "error_msg": "NOERRORS",
                    "check_state": "OK"
                },
                "c2": {
                    "check_status": "PASSED",
                    "check_name": "c2",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                }
            },
            "key2": {
                "c11": {
                    "check_status": "PASSED",
                    "check_name": "c11",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                },
                "c22": {
                    "check_status": "PASSED",
                    "check_name": "c22",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                }
            }
        },
        "Date Universal": "2015-10-19T10:14:03Z",
        "SERVER EXISTENCE": "active"
    }
}

]

The html table im looking for should have a single record for each server and it should show all the errors if exists for the particular server in the same row of the table.

I created a JSfiddle for the code reference herethis fiddle is not the exact script. I can pull servername and other info out to table. but looping into checks and finding out all the failed checks is what im finding hard. can someone please help me out??

Im looking for a fiddle output showing iteration of nested JSON objects for each server and printing only the failed checks and associated errors as output in a table. there are 1k servers and each has key1 checks 20 and key2 checks 20. The controller code is like this

var app=angular.module('angmod', []);
app.controller('ctrl1',function($scope,$http,$interval){
load_data();
$interval(function(){
load_data();
},5000);
function load_data(){
   data=[{
"_index":"servers",
"_id":"server1",
"_score":1,
"_source":{
"list":{
"key1":{"c1"{"check_status":"PASSED","check_name":"c1","error_msg":"NOERRORS","check_state":"OK"},"c2":{"check_status":"PASSED","check_name":"c2","error_msg":"NO ERRORS","check_state":"OK"}},

"key2":{"c11":{"check_status":"PASSED","check_name":"c11","error_msg":"NO ERRORS","check_state":"OK"},"c22":{"check_status":"PASSED","check_name":"c22","error_msg":"NO ERRORS","check_state":"OK"}}
},

"Date Universal":"2015-10-19T10:14:03Z",
"SERVER EXISTENCE":"active"}
}],

"Date Universal":"2015-10-19T10:14:03Z",
"SERVER EXISTENCE":"active"}
},{"_index":"servers",

"_id":"server2",
"_score":1,
"_source":{
"list":{
"key1":{"c1"{"check_status":"PASSED","check_name":"c1","error_msg":"NOERRORS","check_state":"OK"},"c2":{"check_status":"PASSED","check_name":"c2","error_msg":"NO ERRORS","check_state":"OK"}},

"key2":{"c11":{"check_status":"PASSED","check_name":"c11","error_msg":"NO ERRORS","check_state":"OK"},"c22":{"check_status":"PASSED","check_name":"c22","error_msg":"NO ERRORS","check_state":"OK"}}
},

"Date Universal":"2015-10-19T10:14:03Z",
"SERVER EXISTENCE":"active"}
}]
  }]
$scope.qwe=data;
});
};
})

can someone explain the logic???

sasikant
  • 247
  • 1
  • 3
  • 11

0 Answers0