|
| ||||||||||
| Tags: configuration file, error, nagios, perl, perl programming, setup |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Error when filling up my configuration files to set up Nagios
They must complete the configuration files with a string long enough after all, or only two elements are modified (using variable). Therefore it's been a while since I got stuck with a course of a user. So here is what I have laid (of course it does not work, otherwise I would not bother you). Code: #! /usr/bin/perl -w
my $i = 0;
my $v = 52;
for ($i < $v; $i+=1)
{
open (FIC, ">>/usr/local/nagios/etc/objects/network.cfg")
printf ("define service{\n");
printf ("use generic-service\n");
printf ("hostgroups FI026-Switch\n");
printf ("service_description type interface $i\n");
printf ("check_command check_snmp!-C public -o ifType.$i\n");
printf ("}\n");
close (FIC);
exit(1)
} Quote:
|
|
#2
| |||
| |||
| Re: Error when filling up my configuration files to set up Nagios
Several remarks to begin: 1) Learn to use pragmas strict and warnings from the outset that you will forge a way to program cleaner. To indicate the beginning of the script: Code: #! /usr/bin/perl -w use strict; use warnings; Your loop should it not be rather: Code: for ($i = 0; $i < $v; ++$i) 3) The semicolon is missing at the end of this line: Code: open (FIC, ">>/usr/local/nagios/etc/objects/network.cfg") |
|
#3
| |||
| |||
| Re: Error when filling up my configuration files to set up Nagios
First thank you for responsiveness, it's nice! I will correct what you said. Just one thing what is this? use strict; use warnings; Finally, the question is rather what's the use?? |
|
#4
| |||
| |||
| Re: Error when filling up my configuration files to set up Nagios strict requires the developer to declare all the variables he uses in his script. warnings makes the Perl compiler/interpreter more talkative, which lets you know if your code is correct or if there are risks such as certain variables are not properly met. |
|
#5
| |||
| |||
| Re: Error when filling up my configuration files to set up Nagios
Well I modified my code and I placed the opening of the file before the declaration of the loop. This gives the following code: Code: #! /usr/bin/perl -w
use strict;
use warnings;
my $i;
my $v = 52;
open (FIC, ">>/usr/local/nagios/etc/objects/network.cfg");
for ($i=0; $i < $v; ++$i)
{
printf ("define service{\n");
printf ("use generic-service\n");
printf ("hostgroups FI026-Switch\n");
printf ("service_description type interface $i\n");
printf ("check_command check_snmp!-C public -o ifType.$i\n");
printf ("}\n");
}
close (FIC);
exit(1) So I guess it isn't printf that must be used to write to a file (EOF which is more). If anyone knows please let me know. I continue my research on my side. |
|
#6
| |||
| |||
| Re: Error when filling up my configuration files to set up Nagios Quote:
Code: open (FIC, ">>/usr/local/nagios/etc/objects/network.cfg");
for ($i=0; $i < $v; ++$i)
{
print FIC "blablabla";
}
close (FIC); |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Error when filling up my configuration files to set up Nagios" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Windows temp folder is filling up because of etilqs_ files builded by WDsmartware | Girish^techie | Hardware Peripherals | 3 | 22-05-2012 05:32 PM |
| Create more users for Nagios web interface | Svana | Operating Systems | 4 | 12-11-2010 06:32 AM |
| Nagios VS Zabbix | KuNaLBuntU | Polls & Voting | 3 | 25-05-2010 10:48 AM |
| How to install Nagios on Debian | Virtuous | Networking & Security | 5 | 02-03-2010 11:13 AM |
| Filling multiple XML files from an XLS file | MAHAH | Software Development | 4 | 09-12-2009 08:21 PM |