Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


Universal Log Processing Script (tail) / Bind query log

 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
white-jeroen



Joined: 22 Mar 2008
Posts: 22

PostPosted: Sat Mar 22, 2008 11:04 am    Post subject: Universal Log Processing Script (tail) / Bind query log Reply with quote

Hi Guys,

I've written a script in PHP to check what lines are added to a logfile since the last run of the script, and processes them.
The script checks the added lines against the regular expressions set, and increases counters.
These counters can be used in Cacti as 'DERIVE'.

In the attached tgz I use the script to process the Bind querylog.
To be able to use the script for an other log, you need to understand regular epressions.

If you want to use this script exactly as provided please edit 'bindlogstats.php' and check if the settings match your configuration, especially the dirs and files.

I hope the script is usefull for someone else. Please let me know.

Kind regards, Jeroen.



bindlogstats.tgz
 Description:
TGZ with log processing script, and an example to use it to log bind queries. V7

Download
 Filename:  bindlogstats.tgz
 Filesize:  1.33 KB
 Downloaded:  300 Time(s)



Last edited by white-jeroen on Sun Mar 30, 2008 7:17 am; edited 9 times in total
Back to top
white-jeroen



Joined: 22 Mar 2008
Posts: 22

PostPosted: Sat Mar 22, 2008 12:55 pm    Post subject: Reply with quote

I'll add a Graph Template export from Cacti of my Graph, so if someone wants to use this script exactly as is, you can use this template.

I didn't create the graph all by myself, I have customized a template I did find somewhere on this forum.

The graph looks like this:



cacti_graph_template_dns_queries_stacked.xml
 Description:
Graph Template + requires for DNS Queries stacked graph V4

Download
 Filename:  cacti_graph_template_dns_queries_stacked.xml
 Filesize:  46.58 KB
 Downloaded:  259 Time(s)



Last edited by white-jeroen on Mon Mar 24, 2008 5:13 pm; edited 2 times in total
Back to top
white-jeroen



Joined: 22 Mar 2008
Posts: 22

PostPosted: Sat Mar 22, 2008 1:23 pm    Post subject: Installation Tips Reply with quote

Installation Tips

  • Go to the "scripts" dir of your Cacti installation
  • Download the TGZ
  • # tar -xpzf bindlogstats.tgz
  • # mkdir data
  • Edit the bindlogstats.php and update the location of the Bind query log file
  • Also check the if the path of the data dir is correct
  • Make sure the query log is readable by the user that executes the Cacti cron job
  • Make sure the data dir is writable by the user that executes the Cacti cron job
  • Test the script: # ./bindlogstats.php
  • The script creates a file in the data directory. Make sure it is writable by the user that executes the Cacti cron job
  • If you don't have a Bind query log file, add the following to you Bind config:
    Code:
    logging {
      channel queries_file_cacti { file "/var/log/named/queries_cacti.log" versions 3 size 5m; };
      category queries           { queries_file_cacti; };
    };

    Make sure the user 'named' can write tot the queries_cacti.log file.
    Configure the same file in bindlogstats.php as $sLogFile.
[/b]


Last edited by white-jeroen on Mon Mar 24, 2008 5:35 pm; edited 4 times in total
Back to top
sizulku
Cacti User


Joined: 04 Nov 2002
Posts: 110
Location: ACEH

PostPosted: Sun Mar 23, 2008 12:31 am    Post subject: Reply with quote

Hi White-jeroen,

Thanks for the script and template. But it won't work on my system. I've check the query log is readable and data dir is writeable. Got this result below

Quote:
[root@mrtg scripts]# ./bindlogstats.php
a:0 aaaa:0 any:0 cname:0 dnskey:0 mx:0 ns:0 ptr:0 soa:0 spf:0 srv:0 txt:0 total:0
[root@mrtg scripts]#


Quote:
[root@mrtg scripts]# more databindlogstats.php.txt
ByteStart:494969
a:0
aaaa:0
any:0
cname:0
dnskey:0
mx:0
ns:0
ptr:0
soa:0
spf:0
srv:0
txt:0
[root@mrtg scripts]#


Quote:
[root@mrtg scripts]# tail -10 /var/named/query.log
client 203.91.xxx.xxx#33312: query: img165.imageshack.us IN A +
client 203.91.xxx.xxx#32768: query: i.d.com.com IN A +
client 203.91.xxx.xxx#32768: query: img165.imageshack.us IN A +
client 203.91.xxx.xxx#32768: query: ads.digitalpoint.com IN A +
client 203.91.xxx.xxx#32768: query: ad.doubleclick.net IN A +
client 203.91.xxx.xxx#49499: query: www.facebook.com IN A +
client 203.91.xxx.xxx#64312: query: photos-230.friendster.com IN A +
client 203.91.xxx.xxx#32768: query: www.facebook.com IN A +
client 203.91.xxx.xxx#32768: query: s4.ytimg.com IN A +
client 203.91.xxx.xxx#32768: query: media.winamp.com IN A +
[root@mrtg scripts]#


any help would be great. Thanks.

Zul
Back to top
white-jeroen



Joined: 22 Mar 2008
Posts: 22

PostPosted: Sun Mar 23, 2008 4:11 am    Post subject: Reply with quote

I uploaded a new version of the TGZ with updated regular expressions to match your query log.
Back to top
sizulku
Cacti User


Joined: 04 Nov 2002
Posts: 110
Location: ACEH

PostPosted: Sun Mar 23, 2008 9:28 am    Post subject: Reply with quote

Thanks for upcate. But got error dependency while importing to cacti-0.8.7b.


error.jpg
 Description:
 Filesize:  91.9 KB
 Viewed:  9075 Time(s)

error.jpg


Back to top
white-jeroen



Joined: 22 Mar 2008
Posts: 22

PostPosted: Sun Mar 23, 2008 10:32 am    Post subject: Reply with quote

Ai... I don't know how to fix this at the moment. I exported my graph from Cacti Version 0.8., with dependencies. Maybe I'll test the export on a clean install and find out how to fix it later.

Edit: I have found the problem. Some of the datafields were connected to the wrong data input method. I updated the XML. Have fun.
Back to top
white-jeroen



Joined: 22 Mar 2008
Posts: 22

PostPosted: Sun Mar 23, 2008 2:50 pm    Post subject: Reply with quote

I've written an [HOWTO] to be able to use this script to query a remote server. You need to put the scripts from the TGZ on the remote server, and you need to change the Data Input Method from the XML Import to match the settings explained in the Howto.
http://forums.cacti.net/viewtopic.php?p=130433
Back to top
white-jeroen



Joined: 22 Mar 2008
Posts: 22

PostPosted: Mon Mar 24, 2008 8:14 am    Post subject: New version (V6) also working with spine Reply with quote

Sizulku told me he had problems using the script with Spine, so I took some time figuring out what the problem was. I discovered Spine doesn't like a line-end after the output, so I removed it. I uploaded a new version of bindlogstats.tgz (V6).
Back to top
mkoninkx



Joined: 12 Mar 2009
Posts: 1
Location: Netherlands

PostPosted: Thu Mar 12, 2009 4:04 am    Post subject: Reply with quote

Hey White-Jeroen,

First of all, thanks for creating the script!

I've got a small problem with it though, I'm using the script over a SSH RSA tunnel, all outputs give numbers, but the Graph in Cacti show only all that have ever been. When I check the output from the script, the Graph matched all the numbers in there. I've attached a screenshot of my graph, maybe you can have a look at it? and tell me in which way I have to think to solve this.

Second question:
How was your script designed? I'm searching for an explaination for the numbers generated by the bindlogstats.php, shouldn't the numbers output by the script be the difference with the last poll? I'm a bit confused here.

Thanks for you help!



screenshot.jpg
 Description:
Screenshot of Cacti DNS Stacked
 Filesize:  55.94 KB
 Viewed:  5414 Time(s)

screenshot.jpg


Back to top
white-jeroen



Joined: 22 Mar 2008
Posts: 22

PostPosted: Thu Mar 12, 2009 4:31 pm    Post subject: Reply with quote

Hello mkoninkx,

I will first answer your first question:

I see the numbers in your graph only increasing, never decreasing.
I think you need to check the following setting:
    -Log into Cacti as Admin
    -Click "Data Templates" from the right menu
    -Click the right Data Template
    -Look at the lower half of the page
    -For each "Data Source Item" check the following setting:
    -The "Data Source Type" must be "DERIVE"

[edit: answer to second question]

I think this is also the answer to your first question:

A good way to measure increasing values is using the "DERIVE".
When a DNS request is done, for example an A-record, the value is increased by one.
When Cacti asks for an update you just the current value is sent.
Cacti compares it to the last value it received, and devides the difference by the number of seconds passed between the previous measure. Now Cacti knows the average number of DNS request per second during this period. It is no problem when the value gets reset, for example once a day, Cacti detects this and skips that measure.

Kind regards,
Jeroen
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group