#!/usr/bin/Rscript #message(getwd()); checks_info <- utils:::read.table("plugins_hosts_services.tab", sep = "\t", header = TRUE, quote = "", row.names = NULL, check.names = FALSE, as.is = TRUE); ## test_results has a value equal to the exit status of the scripts with arguments command_line_arguments run. check_exit_status <- base:::integer(length = base:::nrow(checks_info)); check_stdout <- base:::character(length = base:::nrow(checks_info)); #test_stderr # <- character(length = length(command_line_arguments)); ## X- stderr output cannot be caught separately yet due to R implementation issue command_lines <- base:::list(); for (test_index in 1L:base:::nrow(checks_info)) { base:::message(base:::paste("Checking", checks_info[test_index,]$description, "...")); command_line <- base:::c(checks_info[test_index,]$`file name`, "-h", checks_info[test_index,]$`-h`); if (checks_info[test_index,]$`-u` != "") { command_line <- base:::c(command_line, '-u', checks_info[test_index,]$`-u`); } if (checks_info[test_index,]$`-b` != "") { command_line <- base:::c(command_line, '-b', checks_info[test_index,]$`-b`); } if (checks_info[test_index,]$`-d` != "") { command_line <- base:::c(command_line, '-d', checks_info[test_index,]$`-d`); } if (!base:::is.na(checks_info[test_index,]$`-p`)) { command_line <- base:::c(command_line, '-p', checks_info[test_index,]$`-p`); } test_output <- base:::system2(command = "python", args = command_line, stdout = TRUE, stderr = TRUE); ## Fetch exit status codes. if(!base:::is.null(base:::attr(test_output, "status"))) { check_exit_status[test_index] <- base:::as.integer(base:::attr(test_output, "status")); } else { check_exit_status[test_index] <- 0L; }; check_stdout[test_index] <- base:::paste(test_output, sep = "\n", collapse = "\n"); command_lines <- base:::c(command_lines, base:::paste(command_line, collapse = " ")); #browser(); } #browser(); test_results_df <- base:::data.frame(description = checks_info$description, command_line = base:::unlist(command_lines), check_exit_status = check_exit_status, check_stdout = check_stdout, stringsAsFactors = FALSE); #browser(); test_results_file_path <- "/tmp/Nagios_checks_test.tab"; utils:::write.table(test_results_df, file = test_results_file_path, col.names = TRUE, row.names = FALSE, sep = "\t"); base:::message(base:::paste("Written test results to TAB-separated table at '", test_results_file_path, "' ...", sep = ""));