summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/mini_epn.c96
-rwxr-xr-xtools/opttest.pl74
-rwxr-xr-xtools/tinderbox_build290
3 files changed, 118 insertions, 342 deletions
diff --git a/tools/mini_epn.c b/tools/mini_epn.c
index 6f3c5d02..1b09f1c1 100644
--- a/tools/mini_epn.c
+++ b/tools/mini_epn.c
@@ -1,14 +1,14 @@
1/* 1/*
2 * 2 *
3 * MINI_EPN.C - Mini Embedded Perl Nagios 3 * MINI_EPN.C - Mini Embedded Perl Nagios
4 * Contributed by Stanley Hopcroft 4 * Contributed by Stanley Hopcroft
5 * Modified by Douglas Warner 5 * Modified by Douglas Warner
6 * Last Modified: 05/02/2002 6 * Last Modified: 05/02/2002
7 * 7 *
8 * This is a sample mini embedded Perl interpreter (hacked out checks.c and 8 * This is a sample mini embedded Perl interpreter (hacked out checks.c and
9 * perlembed) for use in testing Perl plugins. 9 * perlembed) for use in testing Perl plugins.
10 * 10 *
11 * It can be compiled with the following command (see 'man perlembed' for 11 * It can be compiled with the following command (see 'man perlembed' for
12 * more info): 12 * more info):
13 * 13 *
14 * gcc -omini_epn mini_epn.c `perl -MExtUtils::Embed -e ccopts -e ldopts` 14 * gcc -omini_epn mini_epn.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
@@ -21,7 +21,6 @@
21 * 21 *
22 */ 22 */
23 23
24
25#include <EXTERN.h> 24#include <EXTERN.h>
26#include <perl.h> 25#include <perl.h>
27#include <fcntl.h> 26#include <fcntl.h>
@@ -30,7 +29,7 @@
30/* include PERL xs_init code for module and C library support */ 29/* include PERL xs_init code for module and C library support */
31 30
32#if defined(__cplusplus) 31#if defined(__cplusplus)
33#define is_cplusplus 32# define is_cplusplus
34#endif 33#endif
35 34
36#ifdef is_cplusplus 35#ifdef is_cplusplus
@@ -42,22 +41,20 @@ extern "C" {
42 41
43#ifdef is_cplusplus 42#ifdef is_cplusplus
44} 43}
45# ifndef EXTERN_C 44# ifndef EXTERN_C
46# define EXTERN_C extern "C" 45# define EXTERN_C extern "C"
47# endif 46# endif
48#else 47#else
49# ifndef EXTERN_C 48# ifndef EXTERN_C
50# define EXTERN_C extern 49# define EXTERN_C extern
51# endif 50# endif
52#endif 51#endif
53
54 52
55EXTERN_C void xs_init _((void)); 53EXTERN_C void xs_init _((void));
56 54
57EXTERN_C void boot_DynaLoader _((CV* cv)); 55EXTERN_C void boot_DynaLoader _((CV * cv));
58 56
59EXTERN_C void xs_init(void) 57EXTERN_C void xs_init(void) {
60{
61 char *file = __FILE__; 58 char *file = __FILE__;
62 dXSUB_SYS; 59 dXSUB_SYS;
63 60
@@ -65,85 +62,80 @@ EXTERN_C void xs_init(void)
65 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); 62 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
66} 63}
67 64
68
69static PerlInterpreter *perl = NULL; 65static PerlInterpreter *perl = NULL;
70 66
71 67int main(int argc, char **argv, char **env) {
72int main(int argc, char **argv, char **env) 68 char *embedding[] = {"", "p1.pl"};
73{
74 char *embedding[] = { "", "p1.pl" };
75 char plugin_output[1024]; 69 char plugin_output[1024];
76 char buffer[512]; 70 char buffer[512];
77 char tmpfname[32]; 71 char tmpfname[32];
78 char fname[32]; 72 char fname[32];
79 char *args[] = {"","0", "", "", NULL }; 73 char *args[] = {"", "0", "", "", NULL};
80 FILE *fp; 74 FILE *fp;
81 75
82 const int command_line_size = 160; 76 const int command_line_size = 160;
83 char command_line[command_line_size]; 77 char command_line[command_line_size];
84 char *ap ; 78 char *ap;
85 int exitstatus; 79 int exitstatus;
86 int pclose_result; 80 int pclose_result;
87#ifdef THREADEDPERL 81#ifdef THREADEDPERL
88 dTHX; 82 dTHX;
89#endif 83#endif
90 dSP; 84 dSP;
91 85
92 if ((perl=perl_alloc())==NULL) { 86 if ((perl = perl_alloc()) == NULL) {
93 snprintf(buffer,sizeof(buffer),"Error: Could not allocate memory for embedded Perl interpreter!\n"); 87 snprintf(buffer, sizeof(buffer),
94 buffer[sizeof(buffer)-1]='\x0'; 88 "Error: Could not allocate memory for embedded Perl interpreter!\n");
89 buffer[sizeof(buffer) - 1] = '\x0';
95 printf("%s\n", buffer); 90 printf("%s\n", buffer);
96 exit(1); 91 exit(1);
97 } 92 }
98 perl_construct(perl); 93 perl_construct(perl);
99 exitstatus=perl_parse(perl,xs_init,2,embedding,NULL); 94 exitstatus = perl_parse(perl, xs_init, 2, embedding, NULL);
100 if (!exitstatus) { 95 if (!exitstatus) {
101 96
102 exitstatus=perl_run(perl); 97 exitstatus = perl_run(perl);
103 98
104 while(printf("Enter file name: ") && fgets(command_line, command_line_size, stdin)) { 99 while (printf("Enter file name: ") && fgets(command_line, command_line_size, stdin)) {
105 100
106 /* call the subroutine, passing it the filename as an argument */ 101 /* call the subroutine, passing it the filename as an argument */
107 102
108 command_line[strlen(command_line) -1] = '\0'; 103 command_line[strlen(command_line) - 1] = '\0';
109 104
110 strncpy(fname,command_line,strcspn(command_line," ")); 105 strncpy(fname, command_line, strcspn(command_line, " "));
111 fname[strcspn(command_line," ")] = '\x0'; 106 fname[strcspn(command_line, " ")] = '\x0';
112 args[0] = fname ; 107 args[0] = fname;
113 args[3] = command_line + strlen(fname) + 1 ; 108 args[3] = command_line + strlen(fname) + 1;
114 109
115 /* generate a temporary filename to which stdout can be redirected. */ 110 /* generate a temporary filename to which stdout can be redirected. */
116 sprintf(tmpfname,"/tmp/embedded%d",getpid()); 111 sprintf(tmpfname, "/tmp/embedded%d", getpid());
117 args[2] = tmpfname; 112 args[2] = tmpfname;
118 113
119 /* call our perl interpreter to compile and optionally cache the command */ 114 /* call our perl interpreter to compile and optionally cache the command */
120 perl_call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL, args); 115 perl_call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL, args);
121 116
122 perl_call_argv("Embed::Persistent::run_package", G_DISCARD | G_EVAL, args); 117 perl_call_argv("Embed::Persistent::run_package", G_DISCARD | G_EVAL, args);
123 118
124 /* check return status */ 119 /* check return status */
125 if(SvTRUE(ERRSV)){ 120 if (SvTRUE(ERRSV)) {
126 pclose_result=-2; 121 pclose_result = -2;
127 printf("embedded perl ran %s with error %s\n",fname,SvPV(ERRSV,PL_na)); 122 printf("embedded perl ran %s with error %s\n", fname, SvPV(ERRSV, PL_na));
128 } 123 }
129 124
130 /* read back stdout from script */ 125 /* read back stdout from script */
131 fp=fopen(tmpfname, "r"); 126 fp = fopen(tmpfname, "r");
132 127
133 /* default return string in case nothing was returned */ 128 /* default return string in case nothing was returned */
134 strcpy(plugin_output,"(No output!)"); 129 strcpy(plugin_output, "(No output!)");
135
136 fgets(plugin_output,sizeof(plugin_output)-1,fp);
137 plugin_output[sizeof(plugin_output)-1]='\x0';
138 fclose(fp);
139 unlink(tmpfname);
140 printf("embedded perl plugin output was %d,%s\n",pclose_result, plugin_output);
141 130
131 fgets(plugin_output, sizeof(plugin_output) - 1, fp);
132 plugin_output[sizeof(plugin_output) - 1] = '\x0';
133 fclose(fp);
134 unlink(tmpfname);
135 printf("embedded perl plugin output was %d,%s\n", pclose_result, plugin_output);
142 } 136 }
143
144 } 137 }
145 138
146
147 PL_perl_destruct_level = 0; 139 PL_perl_destruct_level = 0;
148 perl_destruct(perl); 140 perl_destruct(perl);
149 perl_free(perl); 141 perl_free(perl);
diff --git a/tools/opttest.pl b/tools/opttest.pl
new file mode 100755
index 00000000..98213082
--- /dev/null
+++ b/tools/opttest.pl
@@ -0,0 +1,74 @@
1#!/usr/bin/perl -w
2use strict;
3use warnings;
4use Test;
5
6# This script (when executed from the monitoring plugins top level directory)
7# executes all the plugins with -h, --help, -V and --version to verify that
8# all of them exit properly with the state UNKNOWN (3)
9
10use vars qw($dir $file $prog $idx $state $output %progs @dirs);
11
12my $tests = 0;
13
14@dirs = qw(plugins plugins-scripts);
15
16foreach my $dir (@dirs) {
17 opendir(DIR, $dir) || die "can't opendir $dir: $!";
18 while ($file = readdir(DIR)) {
19 if (-x "$dir/$file" && -f "$dir/$file") {
20 $tests++;
21 $progs{"$dir/$file"} = $file;
22 }
23 }
24 closedir DIR;
25}
26
27plan tests => $tests;
28
29for my $prog (keys %progs) {
30 $state = 0;
31 $file = `basename $prog`;
32
33 $idx = 1;
34 $output = `$prog -h 2>&1`;
35 if(($? >> 8) != 3) {
36 $state++;
37 print "$prog failed test $idx (help exit code (short form))\n";
38 exit(1);
39 }
40
41 unless ($output =~ m/$progs{$prog}/ms) {
42 $idx++;
43 $state++;
44 print "$output\n$prog failed test $idx\n";
45 }
46
47 $idx++;
48 `$prog --help 2>&1 > /dev/null`;
49 if(($? >> 8) != 3) {
50 $state++;
51 print "$prog failed test $idx (help exit code (long form))\n";
52 exit(1);
53 }
54
55 $idx++;
56 `$prog -V 2>&1 > /dev/null`;
57 if(($? >> 8) != 3) {
58 $state++;
59 print "$prog failed test $idx (version exit code (short form))\n";
60 exit(1);
61 }
62
63 $idx++;
64 `$prog --version 2>&1 > /dev/null`;
65 if(($? >> 8) != 3) {
66 $state++;
67 print "$prog failed test $idx (version exit code (long form))\n";
68 exit(1);
69 }
70
71 print "$prog ($idx tests) ";
72 ok $state,0;
73}
74
diff --git a/tools/tinderbox_build b/tools/tinderbox_build
deleted file mode 100755
index 1a41f577..00000000
--- a/tools/tinderbox_build
+++ /dev/null
@@ -1,290 +0,0 @@
1#!/usr/bin/perl
2# tinderbox_build.pl
3# This script builds the monitoringplugins and then sends
4# logs back to the master tinderbox server
5#
6# This script is based on mozilla-unix.pl which comes with tinderbox2
7#
8# See http://tinderbox.altinity.org for more details
9
10require 5.000;
11
12use strict;
13use Sys::Hostname;
14use Cwd;
15use Time::Local;
16
17my $Version = `git describe --abbrev=4 HEAD`;
18
19my $myhost = hostname;
20chomp($myhost);
21my ($host, $junk) = split(/\./, $myhost);
22
23my $BuildAdministrator = $ENV{TINDERBOX_BUILD_ADMIN} || "$ENV{'USER'}\@$myhost";
24my $TmpDir = $ENV{TMPDIR} || "/tmp";
25
26#Default values of cmdline opts
27my $ReportStatus = 0; # Do not send results to server
28
29# Set these to what makes sense for your system
30
31# Set these proper values for your tinderbox server
32# Have the StrictHostKeyChecking=no so that a new host will automatically add hostkey without
33# prompting. If host key changes, then will get error, so this should still be secure
34my $Tinderbox_server = '-p 1022 -o StrictHostKeyChecking=no tinderbox2@tinderbox.opsera.com';
35
36# These shouldn't really need to be changed
37my $BuildTree = 'monitoringplug';
38my $BuildName = '';
39my $ConfigureArgs = $ENV{CONFIGURE_ARGS};
40
41my $OS = `uname -s`;
42my $OSVer = `uname -r`;
43
44chop($OS, $OSVer);
45
46if ( $OS eq 'AIX' ) {
47 $OSVer = `uname -v`;
48 chop($OSVer);
49 $OSVer = $OSVer . "." . `uname -r`;
50 chop($OSVer);
51}
52
53if ( $OS eq 'IRIX64' ) {
54 $OS = 'IRIX';
55}
56
57if ( $OS eq 'SCO_SV' ) {
58 $OS = 'SCOOS';
59 $OSVer = '5.0';
60}
61
62if ( "$host" ne "" ) {
63 $BuildName = $host . ' ';
64}
65$BuildName .= $OS . ' ' . $OSVer;
66$_ = $BuildName;
67s/ /_/g;
68
69my $logfile = "$_.log";
70
71sub BuildIt {
72 my ($fe, @felist, $EarlyExit, $LastTime);
73
74 my $StartDir = getcwd();
75 $LastTime = 0;
76
77 print "Starting dir is : $StartDir\n";
78
79 my $EarlyExit = 0;
80
81 chdir("$StartDir");
82
83 my $StartTime = time;
84 if (-e (my $file = "monitoring-plugins.spec")) {
85 open F, $file;
86 while (<F>) {
87 if (/^Version: trunk-(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
88 $StartTime = timegm(0, $5, $4, $3, ($2 - 1), ($1 - 1900));
89 last;
90 }
91 }
92 }
93
94 print "Start time is $StartTime",$/;
95
96 my $CurrentDir = getcwd();
97 if ( $CurrentDir ne $StartDir ) {
98 print "startdir: $StartDir, curdir $CurrentDir\n";
99 die "curdir != startdir";
100 }
101
102 unlink( "$logfile" );
103
104 print "opening $logfile\n";
105 open( LOG, ">$logfile" ) || print "can't open $?\n";
106 print LOG "current dir is -- $host:$CurrentDir\n";
107 print LOG "Build Administrator is $BuildAdministrator\n";
108 &PrintEnv;
109
110 my $BuildStatus;
111 if (&configure) {
112 if (&make) {
113 if (&maketest) {
114 $BuildStatus = "success";
115 } else {
116 $BuildStatus = "test_failed";
117 }
118 } else {
119 $BuildStatus = "build_failed";
120 }
121 } else {
122 $BuildStatus = "busted";
123 }
124
125 print LOG "\nBuild Status = $BuildStatus\n";
126
127 close(LOG);
128 chdir("$StartDir");
129
130# TV: Leaving this in, because process mail program probably has some
131# limitation retained
132
133# this fun line added on 2/5/98. do not remove. Translated to english,
134# that's "take any line longer than 1000 characters, and split it into less
135# than 1000 char lines. If any of the resulting lines is
136# a dot on a line by itself, replace that with a blank line."
137# This is to prevent cases where a <cr>.<cr> occurs in the log file. Sendmail
138# interprets that as the end of the mail, and truncates the log before
139# it gets to Tinderbox. (terry weismann, chris yeh)
140#
141# This was replaced by a perl 'port' of the above, written by
142# preed@netscape.com; good things: no need for system() call, and now it's
143# all in perl, so we don't have to do OS checking like before.
144
145 open(LOG, "$logfile") || die "Couldn't open logfile: $!\n";
146 open(OUTLOG, ">${logfile}.last") || die "Couldn't open logfile: $!\n";
147
148 print OUTLOG $/;
149 print OUTLOG "tinderbox: tree: $BuildTree\n";
150 print OUTLOG "tinderbox: builddate: $StartTime\n";
151 print OUTLOG "tinderbox: status: $BuildStatus\n";
152 print OUTLOG "tinderbox: build: $BuildName $fe\n";
153 print OUTLOG "tinderbox: errorparser: unix\n";
154 print OUTLOG "tinderbox: buildfamily: unix\n";
155 print OUTLOG "tinderbox: END\n";
156 print OUTLOG $/;
157
158 while (<LOG>) {
159 my $q = 0;
160
161 for (;;) {
162 my $val = $q * 1000;
163 my $Output = substr($_, $val, 1000);
164
165 last if $Output eq undef;
166
167 $Output =~ s/^\.$//g;
168 $Output =~ s/\n//g;
169 print OUTLOG "$Output\n";
170 $q++;
171 } #EndFor
172
173 } #EndWhile
174
175 close(LOG);
176 close(OUTLOG);
177
178 if ($ReportStatus) {
179 system( "ssh $Tinderbox_server tinderbox_receive < ${logfile}.last" )
180 } else {
181 print <<"EOF"
182Not sending logs to http://tinderbox.altinity.org
183If you have SSH keys setup on the tinderbox server, you can manually send
184with 'ssh $Tinderbox_server tinderbox_receive < ${logfile}.last'
185EOF
186 }
187
188 unlink("$logfile");
189 print "Finished building for tinderbox",$/;
190
191} #EndSub-BuildIt
192
193sub ParseArgs {
194 my($i);
195
196 $i = 0;
197 while( $i < @ARGV ) {
198 if ($ARGV[$i] eq '--version' || $ARGV[$i] eq '-v') {
199 die "$0: version $Version\n";
200 } elsif ($ARGV[$i] eq '-y') {
201 $ReportStatus = 1;
202 } else {
203 &PrintUsage;
204 }
205
206 $i++;
207 } #EndWhile
208
209} #EndSub-ParseArgs
210
211sub PrintUsage {
212 die "usage: $0 [-v | --version ] [-t do not send report to tinderbox server]\n";
213}
214
215sub PrintEnv {
216 my ($key);
217 foreach $key (keys %ENV) {
218 print LOG "$key = $ENV{$key}\n";
219 print "$key = $ENV{$key}\n";
220 }
221
222 # Print the NPTest variables
223 if (-e "/var/tmp/NPTest.cache") {
224 open F, "/var/tmp/NPTest.cache";
225 print LOG "NPTest variables:\n";
226 print LOG <F>;
227 close F;
228 }
229
230} #EndSub-PrintEnv
231
232sub SetupPath {
233 my($Path);
234 $Path = $ENV{PATH};
235 print "Path before: $Path\n";
236
237 # Don't alter path if we're building off a repository tree;
238 # SunOS make will be used only for snapshots and releases.
239 if ( $OS eq 'SunOS' && !( -e '.svn' || -e '.git' )) {
240 $ENV{'PATH'} = '/usr/ccs/bin:' . $ENV{'PATH'};
241 }
242
243 $Path = $ENV{PATH};
244 print "Path After: $Path\n";
245} #EndSub-SetupPath
246
247sub configure {
248 # Configure
249 print LOG "./configure --enable-extra-opts --enable-libtap $ConfigureArgs 2>&1\n";
250 open (CONFIGURE, "./configure --enable-extra-opts --enable-libtap $ConfigureArgs 2>&1 |") || die "../configure: $!\n";
251 while (<CONFIGURE>) {
252 print $_;
253 print LOG $_;
254 }
255 close(CONFIGURE);
256 return ! $?;
257}
258
259sub make {
260 # Building
261 print LOG "make 2>&1\n";
262 open( MAKE, "make 2>&1 |");
263 while ( <MAKE> ) {
264 print $_;
265 print LOG $_;
266 }
267 close( MAKE);
268 return ! $?;
269}
270
271sub maketest {
272 # Tests
273 print LOG "LANG=C make test 2>&1 && make install DESTDIR=$TmpDir/tinderbox_build.$$ 2>&1 && make install-strip DESTDIR=$TmpDir/tinderbox_build2.$$ 2>&1\n";
274 open( MAKE, "LANG=C make test 2>&1 && make install DESTDIR=$TmpDir/tinderbox_build.$$ 2>&1 && make install-strip DESTDIR=$TmpDir/tinderbox_build2.$$ 2>&1 |");
275 while ( <MAKE> ) {
276 print $_;
277 print LOG $_;
278 }
279 close( MAKE);
280 my $rc = $?;
281 system("rm -fr $TmpDir/tinderbox_build.$$ $TmpDir/tinderbox_build2.$$");
282 return ! $rc;
283}
284
285# Main function
286&ParseArgs;
287&SetupPath;
288&BuildIt;
289
2901;