Hi, I'm newbie here and I have a question.
I try to develop the RESTFul nagios that it is my senior project. I
setup the MK Livestatus into my nagios server.
First, I try to set "OutputFormat: json" and I write the program to
parse this JSON. I use the library called "GSON". But, it not works..
I just try following code..
String b = "[[1,0,0,\"\",\"\",1,\"192.168.1.104\",\"My Windows
Server\",\"check-host-alive\",0,5.0000000000e+00,0,\"24x7\",0,1,
,
,
]]";
Object
test = gson.fromJson(b, Object
.class);
I got an error....
"array element type mismatch
java.lang.IllegalArgumentException: array element type mismatch"
First question is " Anyone has the idea about parse JSON in JAVA " ???
Next, so I try to change the OutputFormat to CSV. But It not works too.
I found the problem from if we try to query "perf_data" the result
from this query will make a problem.
The result it like " rta=0.433000ms;3000.000000;5000.000000;0.000000
pl=0%;80;100;0 "
From the result, it have a SEMICOLON that is the column separator.
So, I write the program that use the SEMICOLON to separate the column
and it make the Header column not equal to the row column.
Second question is " This is bug ?? or If is not bug, how I deal with
this situation ?
Sorry for my bad English..
Thank you..
JSON is not designed to be created by hand and is in fact very error prone when doing it this way. You should use (usually standard or module library) functions to generate your JSON strings, usually you would make an object like a multi-dimensional array and then run it through your generator function. I don't know much about Java but in Python I use the json standard library to handle just about everything I need.
For more help you should probably try a Java support forum or IRC channel.
On Nov 11, 2010, at 9:49 AM, ATOM MUICT#5 wrote:
Hi, I'm newbie here and I have a question.
I try to develop the RESTFul nagios that it is my senior project. I
setup the MK Livestatus into my nagios server.
First, I try to set "OutputFormat: json" and I write the program to
parse this JSON. I use the library called "GSON". But, it not works..
I just try following code..
String b = "[[1,0,0,\"\",\"\",1,\"192.168.1.104\",\"My Windows
Server\",\"check-host-alive\",0,5.0000000000e+00,0,\"24x7\",0,1,
,
,
]]";
Object
test = gson.fromJson(b, Object
.class);
I got an error....
"array element type mismatch
java.lang.IllegalArgumentException: array element type mismatch"
First question is " Anyone has the idea about parse JSON in JAVA " ???
Next, so I try to change the OutputFormat to CSV. But It not works too.
I found the problem from if we try to query "perf_data" the result
from this query will make a problem.
The result it like " rta=0.433000ms;3000.000000;5000.000000;0.000000
pl=0%;80;100;0 "
From the result, it have a SEMICOLON that is the column separator.
So, I write the program that use the SEMICOLON to separate the column
and it make the Header column not equal to the row column.
Second question is " This is bug ?? or If is not bug, how I deal with
this situation ?
Sorry for my bad English..
Thank you..
_______________________________________________
checkmk-en mailing list
[email protected]
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
Hi, I'm newbie here and I have a question.
I try to develop the RESTFul nagios that it is my senior project. I
setup the MK Livestatus into my nagios server.
First, I try to set "OutputFormat: json" and I write the program to
parse this JSON. I use the library called "GSON". But, it not works..
I just try following code..
String b = "[[1,0,0,\"\",\"\",1,\"192.168.1.104\",\"My Windows
Server\",\"check-host-alive\",0,5.0000000000e+00,0,\"24x7\",0,1,
,
,
]]";
Object
test = gson.fromJson(b, Object
.class);
I got an error....
"array element type mismatch
java.lang.IllegalArgumentException: array element type mismatch"
First question is " Anyone has the idea about parse JSON in JAVA " ???
So b is an example string of what you get from mk_livestatus. As I interpret
http://sites.google.com/site/gson/gson-user-guide
it is very problematic to resolve the nested types you have in the mk response:
Array of ( Array of ( Int, Int, Int, String, .... ) )
Maybe you should discuss this problem on the gson discussion list. I think you have to design a class which these responses can be mapped into by gson. Object seems to generic for the deserializer.
Next, so I try to change the OutputFormat to CSV. But It not works too.
I found the problem from if we try to query "perf_data" the result
from this query will make a problem.
The result it like " rta=0.433000ms;3000.000000;5000.000000;0.000000
pl=0%;80;100;0 "
From the result, it have a SEMICOLON that is the column separator.
So, I write the program that use the SEMICOLON to separate the column
and it make the Header column not equal to the row column.
Second question is " This is bug ?? or If is not bug, how I deal with
this situation ?
Have you respected the quoting strings used for the perfdata in your example? Maybe your CSV parser misses the point that tha semicolon ist part of the string data instead of a field separator. There are many ready-to-go parser available. Try one from the apache commons or opencsv (
opencsv –
)
Good luck,
Stefan
Am 11.11.2010 15:49, schrieb ATOM MUICT#5:
This is my code for deal with CVS.
nagios.makeQuery("GET hosts\n"
+ "ResponseHeader: fixed16\n"
+ "\n\n");
This is output
"200 3789
accept_passive_checks;acknowledged;acknowledgement_type;action_url;action_url_expanded;active_checks_enabled;address;alias;check_command;check_freshness;check_interval;check_options;check_period;check_type;checks_enabled;childs;comments;comments_with_info;contacts;current_attempt;current_notification_number;custom_variable_names;custom_variable_values;display_name;downtimes;downtimes_with_info;event_handler_enabled;execution_time;first_notification_delay;flap_detection_enabled;groups;hard_state;has_been_checked;high_flap_threshold;icon_image;icon_image_alt;icon_image_expanded;in_check_period;in_notification_period;initial_state;is_executing;is_flapping;last_check;last_hard_state;last_hard_state_change;last_notification;last_state;last_state_change;last_time_down;last_time_unreachable;last_time_up;latency;long_plugin_output;low_flap_threshold;max_check_attempts;modified_attributes;modified_attributes_list;name;next_check;next_notification;notes;notes_expanded;notes_url;notes_url_expanded;notification_interval;notification_period;notifications_enabled;num_services;num_services_crit;num_services_hard_crit;num_services_hard_ok;num_services_hard_unknown;num_services_hard_warn;num_services_ok;num_services_pending;num_services_unknown;num_services_warn;obsess_over_host;parents;pending_flex_downtime;percent_state_change;perf_data;plugin_output;process_performance_data;retry_interval;scheduled_downtime_depth;services;services_with_state;state;state_type;statusmap_image;total_services;worst_service_hard_state;worst_service_state;x_3d;y_3d;z_3d
1;0;0;;;1;192.168.1.104;My Windows
Server;check-host-alive;0;5.0000000000e+00;0;24x7;0;1;;;;nagiosadmin;1;0;;;at0m-laptop;;;1;4.0095690000e+00;0.0000000000e+00;1;windows-servers;0;1;0.0000000000e+00;;;;1;1;0;0;0;1289492747;0;1289450217;0;0;1289483447;1289483387;0;1289492757;2.2000000000e-02;;0.0000000000e+00;10;0;;at0m-laptop;1289493057;0;;;;;3.0000000000e+01;24x7;1;7;1;1;6;0;0;6;0;0;0;1;;0;0.0000000000e+00;rta=0.815000ms;3000.000000;5000.000000;0.000000
pl=0%;80;100;0;PING OK - Packet loss = 0%, RTA = 0.81
ms;1;1.0000000000e+00;0;W3SVC,Uptime,NSClient++ Version,Memory
Usage,Explorer,CPU Load,C:\ Drive
Space;W3SVC|2|1,Uptime|0|1,NSClient++ Version|0|1,Memory
Usage>0|1,Explorer|0|1,CPU Load|0|1,C:\ Drive
Space>0|1;0;1;;7;2;2;0.0000000000e+00;0.0000000000e+00;0.0000000000e+00
1;0;0;;;1;127.0.0.1;localhost;check-host-alive;0;5.0000000000e+00;0;24x7;0;1;;;;nagiosadmin;1;0;;;localhost;;;1;4.0070840000e+00;0.0000000000e+00;1;linux-servers;0;1;0.0000000000e+00;;;;1;0;0;0;0;1289492797;0;1287244061;0;0;1288795901;1288795901;0;1289492807;7.4000000000e-02;;0.0000000000e+00;10;0;;localhost;1289493107;0;;;;;1.2000000000e+02;workhours;1;8;0;0;8;0;0;8;0;0;0;1;;0;0.0000000000e+00;rta=0.035000ms;3000.000000;5000.000000;0.000000
pl=0%;80;100;0;PING OK - Packet loss = 0%, RTA = 0.04
ms;1;1.0000000000e+00;0;Total Processes,Swap Usage,SSH,Root
Partition,PING,HTTP,Current Users,Current Load;Total
Processes>0|1,Swap Usage|0|1,SSH|0|1,Root
Partition>0|1,PING|0|1,HTTP|0|1,Current Users|0|1,Current
Load>0|1;0;1;;8;0;0;0.0000000000e+00;0.0000000000e+00;0.0000000000e+00
1;0;0;;;1;192.168.1.104;My First Windows
Server;check-host-alive;0;5.0000000000e+00;0;24x7;0;1;;58,59;58|Nagios
Admin>test,59|Nagios
Admin>eeeeee;nagiosadmin;1;0;;;windowshost;;;1;4.0169380000e+00;0.0000000000e+00;1;;0;1;0.0000000000e+00;;;;1;1;0;0;0;1289492687;0;1289449947;0;0;1289483397;1289483327;0;1289492697;2.2200000000e-01;;0.0000000000e+00;10;0;;windowshost;1289492997;0;;;;;3.0000000000e+01;24x7;1;1;0;0;1;0;0;1;0;0;0;1;;0;0.0000000000e+00;rta=3.881000ms;3000.000000;5000.000000;0.000000
pl=0%;80;100;0;PING OK - Packet loss = 0%, RTA = 3.88
ms;1;1.0000000000e+00;0;CPU Load;CPU
Load>0|1;0;1;;1;0;0;0.0000000000e+00;0.0000000000e+00;0.0000000000e+00
So, total of column header is should equal to total column of each
dataset, right ?
Total of column header = 97
Then, suppose I already split column header out.
And then use this code to separate dataset.
row.split(";");
The total of array that I split is 103
I try to debug that I already said in previous posted.
I found that if I just query
"GET hosts\n"
+ "Columns:name perf_data\n"
+ "Filter: name = at0m-laptop\n"
+ "ResponseHeader: fixed16\n"
+ "\n\n";
200 75
at0m-laptop;rta=3.699000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
The query that had "pref_data" will produce the ";".
So, when I use the "row.split(";");" , total of column header (2) not
equal to total column of dataset(8) of this example.
Best Regard,
Korrawit Yindeeyoungyeon (ATOM)
On Thu, Nov 11, 2010 at 11:02 PM, Stefan Mayr <[email protected]> wrote:
Am 11.11.2010 15:49, schrieb ATOM MUICT#5:
Hi, I'm newbie here and I have a question.
I try to develop the RESTFul nagios that it is my senior project. I
setup the MK Livestatus into my nagios server.
First, I try to set "OutputFormat: json" and I write the program to
parse this JSON. I use the library called "GSON". But, it not works..
I just try following code..
String b = "\[\[1,0,0,\\"\\",\\"\\",1,\\"192\.168\.1\.104\\",\\"My Windows
Server\",\"check-host-alive\",0,5.0000000000e+00,0,\"24x7\",0,1,,,]]";
Object test = gson.fromJson(b, Object.class);
I got an error\.\.\.\.
"array element type mismatch
java\.lang\.IllegalArgumentException: array element type mismatch"
First question is " Anyone has the idea about parse JSON in JAVA " ???
So b is an example string of what you get from mk_livestatus. As I interpret
http://sites.google.com/site/gson/gson-user-guide it is very problematic to
resolve the nested types you have in the mk response:
Array of ( Array of ( Int, Int, Int, String, .... ) )
Maybe you should discuss this problem on the gson discussion list. I think
you have to design a class which these responses can be mapped into by gson.
Object seems to generic for the deserializer.
Next, so I try to change the OutputFormat to CSV. But It not works too.
I found the problem from if we try to query "perf_data" the result
from this query will make a problem.
The result it like " rta=0.433000ms;3000.000000;5000.000000;0.000000
pl=0%;80;100;0 "
From the result, it have a SEMICOLON that is the column separator.
So, I write the program that use the SEMICOLON to separate the column
and it make the Header column not equal to the row column.
Second question is " This is bug ?? or If is not bug, how I deal with
this situation ?
Have you respected the quoting strings used for the perfdata in your
example? Maybe your CSV parser misses the point that tha semicolon ist part
of the string data instead of a field separator. There are many ready-to-go
parser available. Try one from the apache commons or opencsv
(opencsv –)
Good luck,
Stefan
_______________________________________________
checkmk-en mailing list
[email protected]
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
okay, now I can see the problem: livestatus does not quote fields that contain the fieldseparator or the separator itself. I guess this should be considered as a bug.
As a workaround you could calculate the difference of header to data columns and merge the performance data back.
Stefan
Am 11.11.2010 17:55, schrieb Korrawit Yindeeyoungyeon:
So, total of column header is should equal to total column of each
dataset, right ?
Total of column header = 97
Then, suppose I already split column header out.
And then use this code to separate dataset.
row.split(";");
The total of array that I split is 103
I try to debug that I already said in previous posted.
I found that if I just query
"GET hosts\n"
+ "Columns:name perf_data\n"
+ "Filter: name = at0m-laptop\n"
+ "ResponseHeader: fixed16\n"
+ "\n\n";
200 75
at0m-laptop;rta=3.699000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
The query that had "pref_data" will produce the ";".
So, when I use the "row.split(";");" , total of column header (2) not
equal to total column of dataset(8) of this example.
Best Regard,
Korrawit Yindeeyoungyeon (ATOM)
using CSV is intended for simple environments like the Shell, where quoting is difficult to handle. If you want to use CSV for more complex queres, use FieldSeparators: 0 1 2 3 to use non-printable ASCII characters as separators.
Mathias Kettner
Linux- und OpenSource Experte
www.mathias-kettner.de
Am 11.11.2010 um 21:04 schrieb Stefan Mayr <[email protected]>:
Am 11.11.2010 17:55, schrieb Korrawit Yindeeyoungyeon:
So, total of column header is should equal to total column of each
dataset, right ?
Total of column header = 97
Then, suppose I already split column header out.
And then use this code to separate dataset.
row.split(";");
The total of array that I split is 103
I try to debug that I already said in previous posted.
I found that if I just query
"GET hosts\n"
+ "Columns:name perf_data\n"
+ "Filter: name = at0m-laptop\n"
+ "ResponseHeader: fixed16\n"
+ "\n\n";
200 75
at0m-laptop;rta=3.699000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
The query that had "pref_data" will produce the ";".
So, when I use the "row.split(";");" , total of column header (2) not
equal to total column of dataset(8) of this example.
Best Regard,
Korrawit Yindeeyoungyeon (ATOM)
okay, now I can see the problem: livestatus does not quote fields that contain the fieldseparator or the separator itself. I guess this should be considered as a bug.
As a workaround you could calculate the difference of header to data columns and merge the performance data back.
Stefan
_______________________________________________
checkmk-en mailing list
[email protected]
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
using CSV is intended for simple environments like the Shell, where quoting is difficult to handle. If you want to use CSV for more complex queres, use FieldSeparators: 0 1 2 3 to use non-printable ASCII characters as separators.
Mathias Kettner
Linux- und OpenSource Experte
www.mathias-kettner.de
Am 11.11.2010 um 21:04 schrieb Stefan Mayr <[email protected]>:
Am 11.11.2010 17:55, schrieb Korrawit Yindeeyoungyeon:
So, total of column header is should equal to total column of each
dataset, right ?
Total of column header = 97
Then, suppose I already split column header out.
And then use this code to separate dataset.
row\.split\(";"\);
The total of array that I split is 103
I try to debug that I already said in previous posted.
I found that if I just query
"GET hosts\\n"
\+ "Columns:name perf\_data\\n"
\+ "Filter: name = at0m\-laptop\\n"
\+ "ResponseHeader: fixed16\\n"
\+ "\\n\\n";
200 75
at0m-laptop;rta=3.699000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
The query that had "pref_data" will produce the ";".
So, when I use the "row.split(";");" , total of column header (2) not
equal to total column of dataset(8) of this example.
Best Regard,
Korrawit Yindeeyoungyeon \(ATOM\)
okay, now I can see the problem: livestatus does not quote fields that contain the fieldseparator or the separator itself. I guess this should be considered as a bug.
As a workaround you could calculate the difference of header to data columns and merge the performance data back.
Stefan
_______________________________________________
checkmk-en mailing list
[email protected]
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
_______________________________________________
checkmk-en mailing list
[email protected]
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
On Fri, Nov 12, 2010 at 5:38 PM, Korrawit Yindeeyoungyeon <[email protected]> wrote:
Thanks Stefan.
On Fri, Nov 12, 2010 at 2:23 AM, Mathias Kettner <[email protected]> wrote:
using CSV is intended for simple environments like the Shell, where quoting is difficult to handle. If you want to use CSV for more complex queres, use FieldSeparators: 0 1 2 3 to use non-printable ASCII characters as separators.
Mathias Kettner
Linux- und OpenSource Experte
www.mathias-kettner.de
Am 11.11.2010 um 21:04 schrieb Stefan Mayr <[email protected]>:
Am 11.11.2010 17:55, schrieb Korrawit Yindeeyoungyeon:
So, total of column header is should equal to total column of each
dataset, right ?
Total of column header = 97
Then, suppose I already split column header out.
And then use this code to separate dataset.
row\.split\(";"\);
The total of array that I split is 103
I try to debug that I already said in previous posted.
I found that if I just query
"GET hosts\\n"
\+ "Columns:name perf\_data\\n"
\+ "Filter: name = at0m\-laptop\\n"
\+ "ResponseHeader: fixed16\\n"
\+ "\\n\\n";
200 75
at0m-laptop;rta=3.699000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
The query that had "pref_data" will produce the ";".
So, when I use the "row.split(";");" , total of column header (2) not
equal to total column of dataset(8) of this example.
Best Regard,
Korrawit Yindeeyoungyeon \(ATOM\)
okay, now I can see the problem: livestatus does not quote fields that contain the fieldseparator or the separator itself. I guess this should be considered as a bug.
As a workaround you could calculate the difference of header to data columns and merge the performance data back.
Stefan
_______________________________________________
checkmk-en mailing list
[email protected]
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
_______________________________________________
checkmk-en mailing list
[email protected]
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en