HELP! Graphing from text file

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
fredrlun
Posts: 7
Joined: Sun Aug 30, 2015 8:54 pm

HELP! Graphing from text file

Post by fredrlun »

Hi all,

Not sure if this is the right place(mod please redirect me to right place if not)

Scenario is that im trying to get cacti to graph from a text file(Which as i have read and hopefully understood should be a easy task). Yes i have read multiple howtos and docs.cacti.net.
I have a perl script logging some output from a Cisco to a textfile, i then have another perl script printing the last line in the logfile. Reason for this is because the output from the Cisco is containing more info then i need to graph.(After some awk magic)
When i run the script from the unix box, the output is correct.

Code: Select all

[abc@def ~]$ ./abc.pl 
20528[abc@def ~]$ 
But cacti log says:

Code: Select all

08/31/2015 03:59:31 AM - CMDPHP: Poller[0] Host[0] DS[19] CMD: /home/abc/123.pl, output: U
08/31/2015 03:59:31 AM - CMDPHP: Poller[0] Host[0] DS[19] WARNING: Result from CMD not valid. Partial Result: U
Is the poller.php reading this data wrong? I am stuck as i cant see why this shouldnt work

I hope this makes sense and that you can guide me the right way to getting this done.

For testing i have a set up a perl script printing random numbers and this is graphing fine, but this script isnt getting the input from a text file..
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: HELP! Graphing from text file

Post by phalek »

Is the poller able to call that script ( execute permissions )
AND
Is the poller able to read the log which the script parses ( read permissions )
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
fredrlun
Posts: 7
Joined: Sun Aug 30, 2015 8:54 pm

Re: HELP! Graphing from text file

Post by fredrlun »

Hi again,

Thanks for fast reply.

Yes, the poller is able to execute the script.
Yes the poller has permissions to read the .txt file.

As mentioned earlier i have another perl script running just for testing which is generating random numbers, this is working fine.

When i switch between input methods(from random generator to the script who is parsing info from txt file) the graph starts graphing.
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: HELP! Graphing from text file

Post by phalek »

Not sure if you'Re using SELinux, but this may interfere with the reading of that other txt file. Can you check if you are running it and temporary disable it if it is ?
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
fredrlun
Posts: 7
Joined: Sun Aug 30, 2015 8:54 pm

Re: HELP! Graphing from text file

Post by fredrlun »

Hi,

SELinux isnt the issue here as the logfile and script are in the same folder and has the same permissions
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: HELP! Graphing from text file

Post by phalek »

Processes and files are labeled with an SELinux context that contains additional information, such as an SELinux user, role, type, and, optionally, a level. When running SELinux, all of this information is used to make access control decisions.
Execute the following on the files to check their context. Remember: SELinux goes way beyond simple permissions and the SELinux context is "stuck" on the file regardless of it's location.

Code: Select all

ls -Z file1
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
fredrlun
Posts: 7
Joined: Sun Aug 30, 2015 8:54 pm

Re: HELP! Graphing from text file

Post by fredrlun »

Yes, have checked ls -Z

Both of the files have this context:
unconfined_u:object_r:user_home_t:s0


But some interestingly happend at 11:38 today:

Code: Select all

08/31/2015 11:38:31 AM - CMDPHP: Poller[0] Host[0] DS[19] CMD: /home/abc/123.pl, output: 14659
But since then the output stays the same, although the logfile is updating with the latest input from the Cisco.
fredrlun
Posts: 7
Joined: Sun Aug 30, 2015 8:54 pm

Re: HELP! Graphing from text file

Post by fredrlun »

Perl script which is parsing test.txt(logfile)

Code: Select all

#!/usr/bin/perl
open(PROCESS, "tail -n1 test.txt |");
$siste = <PROCESS>;
close(PROCESS);
chomp $siste;
print $siste;
output:

Code: Select all

[abc@def ~]$ ./123.pl 
30078[abc@def ~]$ 
And the test.txt file looks something like this:

Code: Select all

27347
8976
3750
1261
23837
16470
20006
10385
23820
25787
160
18393
30176
30078
Basically just numbers generated from another perl script. Ive just used this to generate numbers into the test.txt

Code: Select all

while(true); do echo $[ 1 + $[ RANDOM % 100000 ]] | tee -a test.txt; sleep 20; done

As you can see from the last picture.. The graph is graphing, but its graphing a bogus number. Its graphin 14659 which was a number for 23 instances ago.

Data input:
Image
Data Source:
Image
Graph:
Image
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: HELP! Graphing from text file

Post by phalek »

Code: Select all

open(PROCESS, "tail -n1 test.txt |");
Shouldn't this be a "full path" instead of just "test.txt" ( /path/to/test.txt ) ? Unless you did rewrite it for posting here ...
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
fredrlun
Posts: 7
Joined: Sun Aug 30, 2015 8:54 pm

Re: HELP! Graphing from text file

Post by fredrlun »

Hi all again,

Thanks for replying and throwing me in the right direction. I have rewrited the script which cacti is using to get the output, and its working.

But i have another problem now. I sometimes get "WARNING: Result from CMD not valid. Partial Result: U"

I can see from the logfiles generated from my script that the cronjob and script is running and getting the info from the Cisco.

But Cacti poller seems to miss the output from time to time.

Do you have any suggestions on what to look for?
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests