source: monitoring/plugins/mpi/integration_test.R @ 3313

Last change on this file since 3313 was 3313, checked in by sanmai, 11 years ago
  • Fix handling of -d command line parameter.
  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/usr/bin/Rscript
2#message(getwd());
3
4checks_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
15check_exit_status <-
16    base:::integer(length = base:::nrow(checks_info));
17check_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
23command_lines <-
24    base:::list();
25
26for (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
50    test_output <-
51        base:::system2(command = "python2",
52                        args    = command_line,
53                        stdout  = TRUE,
54                        stderr  = TRUE);
55
56    ## Fetch exit status codes. 
57    if(!base:::is.null(base:::attr(test_output, "status"))) {
58        check_exit_status[test_index] <-
59            base:::as.integer(base:::attr(test_output, "status"));
60    } else {
61        check_exit_status[test_index] <-
62            0L;
63    };
64
65    check_stdout[test_index] <-
66        base:::paste(test_output,
67                      sep = "\n",
68                      collapse = "\n");
69
70    command_lines <-
71        base:::c(command_lines, base:::paste(command_line, collapse = " "));
72
73    #browser();
74}
75
76#browser();
77
78test_results_df <-
79    base:::data.frame(description             = checks_info$description,
80                      command_line            = base:::unlist(command_lines),
81                      check_exit_status       = check_exit_status,
82                      check_stdout            = check_stdout,
83                      stringsAsFactors        = FALSE);
84
85#browser();
86
87test_results_file_path <-
88    "/tmp/Nagios_checks_test.tab";
89
90utils:::write.table(test_results_df,
91                   file            = test_results_file_path,
92                   col.names       = TRUE,
93                   row.names       = FALSE,
94                   sep             = "\t");
95
96base:::message(base:::paste("Written test results to TAB-separated table at '", test_results_file_path, "' ...", sep = ""));
Note: See TracBrowser for help on using the repository browser.