1 | #!/usr/bin/Rscript |
---|
2 | #message(getwd()); |
---|
3 | |
---|
4 | checks_info <- |
---|
5 | utils:::read.table("plugins_hosts_services.tab", |
---|
6 | sep = "\t", |
---|
7 | header = TRUE, |
---|
8 | quote = "", |
---|
9 | row.names = NULL, |
---|
10 | check.names = FALSE, |
---|
11 | as.is = TRUE); |
---|
12 | |
---|
13 | ## test_results has a value equal to the exit status of the scripts with arguments command_line_arguments run. |
---|
14 | |
---|
15 | check_exit_status <- |
---|
16 | base:::integer(length = base:::nrow(checks_info)); |
---|
17 | check_stdout <- |
---|
18 | base:::character(length = base:::nrow(checks_info)); |
---|
19 | #test_stderr |
---|
20 | # <- character(length = length(command_line_arguments)); |
---|
21 | ## X- stderr output cannot be caught separately yet due to R implementation issue |
---|
22 | |
---|
23 | command_lines <- |
---|
24 | base:::list(); |
---|
25 | |
---|
26 | for (test_index in 1L:base:::nrow(checks_info)) |
---|
27 | { |
---|
28 | base:::message(base:::paste("Checking", checks_info[test_index,]$description, "...")); |
---|
29 | |
---|
30 | command_line <- |
---|
31 | base:::c(checks_info[test_index,]$`file name`, |
---|
32 | "-h", checks_info[test_index,]$`-h`); |
---|
33 | |
---|
34 | if (checks_info[test_index,]$`-u` != "") { |
---|
35 | command_line <- |
---|
36 | base:::c(command_line, |
---|
37 | '-u', checks_info[test_index,]$`-u`); |
---|
38 | } |
---|
39 | if (checks_info[test_index,]$`-b` != "") { |
---|
40 | command_line <- |
---|
41 | base:::c(command_line, |
---|
42 | '-b', checks_info[test_index,]$`-b`); |
---|
43 | } |
---|
44 | if (checks_info[test_index,]$`-d` != "") { |
---|
45 | command_line <- |
---|
46 | base:::c(command_line, |
---|
47 | '-d', checks_info[test_index,]$`-d`); |
---|
48 | } |
---|
49 | if (!base:::is.na(checks_info[test_index,]$`-p`)) { |
---|
50 | command_line <- |
---|
51 | base:::c(command_line, |
---|
52 | '-p', checks_info[test_index,]$`-p`); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | test_output <- |
---|
57 | base:::system2(command = "python", |
---|
58 | args = command_line, |
---|
59 | stdout = TRUE, |
---|
60 | stderr = TRUE); |
---|
61 | |
---|
62 | ## Fetch exit status codes. |
---|
63 | if(!base:::is.null(base:::attr(test_output, "status"))) { |
---|
64 | check_exit_status[test_index] <- |
---|
65 | base:::as.integer(base:::attr(test_output, "status")); |
---|
66 | } else { |
---|
67 | check_exit_status[test_index] <- |
---|
68 | 0L; |
---|
69 | }; |
---|
70 | |
---|
71 | check_stdout[test_index] <- |
---|
72 | base:::paste(test_output, |
---|
73 | sep = "\n", |
---|
74 | collapse = "\n"); |
---|
75 | |
---|
76 | command_lines <- |
---|
77 | base:::c(command_lines, base:::paste(command_line, collapse = " ")); |
---|
78 | |
---|
79 | #browser(); |
---|
80 | } |
---|
81 | |
---|
82 | #browser(); |
---|
83 | |
---|
84 | test_results_df <- |
---|
85 | base:::data.frame(description = checks_info$description, |
---|
86 | command_line = base:::unlist(command_lines), |
---|
87 | check_exit_status = check_exit_status, |
---|
88 | check_stdout = check_stdout, |
---|
89 | stringsAsFactors = FALSE); |
---|
90 | |
---|
91 | #browser(); |
---|
92 | |
---|
93 | test_results_file_path <- |
---|
94 | "/tmp/Nagios_checks_test.tab"; |
---|
95 | |
---|
96 | utils:::write.table(test_results_df, |
---|
97 | file = test_results_file_path, |
---|
98 | col.names = TRUE, |
---|
99 | row.names = FALSE, |
---|
100 | sep = "\t"); |
---|
101 | |
---|
102 | base:::message(base:::paste("Written test results to TAB-separated table at '", test_results_file_path, "' ...", sep = "")); |
---|