473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Converting timestamps and IP addresses

Hi,

I'm building a central logging system for security applications as my master
thesis, but I've run into some troubles:

Different applications make database logs using different formats:
- Timestamps as timestamps or as numeric values
- IP addresses in dotted notation (aaa.bbb.ccc.ddd) or as numeric values

I'd like to convert these to the same type, so that I can compare them. Two
questions thereby:
- Is there an easy way with built-in functions? (I didn't found them)
- Can I use triggers and C-functions to reach my goal?

For the second question: in that case, all tables in my database would have
the same dataformat for timestamps and IP's, and conversion would happen at
insertion. However, there could be a data type mismatch between what stays in
the query (a numeric value for instance) and the column type in the database
(string type: dotted notation for IP): So, when are the types checked? Before
or after a trigger on INSERT? (Of course when using a TRIGGER BEFORE INSERT
:-)) I'm only wondering when type checks are executed...

If anyone has built such functions already, I'd gladly accept, and you can win
a line in my thank word ;-)

Greetings,
Erwin Van de Velde
Student of University of Antwerp,
Belgium
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 22 '05 #1
1 2374
Le Mercredi 11 Février 2004 12:12, Erwin Van de Velde a écrit :
If anyone has built such functions already, I'd gladly accept, and you can
win a line in my thank word ;-)


Dear Erwin,

I built a small centralised database built for Ulogd and ran into the same
questions. You can either use implicit or explicit CASTs:

SELECT '192.168.0.3'::inet AS myexplicitcast
will convert a string into an inet

Sometimes, when you do not have contol over the logging deamon sending queries
(which is the case for example of Ulogd), you may be obliged to use implicit
CASTs (a solution described in PostgreSQL bits):

CREATE OR REPLACE FUNCTION ulog_timecast(int4)
RETURNS timestamp AS
'select "timestamp"($1::abstime);'
LANGUAGE 'sql' VOLATILE;

CREATE CAST (int4 AS timestamp)
WITH FUNCTION ulog_timecast(int4)
AS IMPLICIT;

In the end, you may need to add fields to your table and compute the logs when
they are received, using triggers and procedures (better STABLE ones). But
this can slow down logging. You may also prefer to run cron jobs (my volume
is too small for such optimisations). Also, do not forget using partial
indexes.

Using PostgreSQL on a double-athlon server, I can log up to 1000 messages
every second, but I did not try to stress the server too long (it should not
be a problem with partial indexing).

If you are interested in my code, just drop me an email and I will send you
the dump (just a few functions and triggers).

Next week, I plan to use PLbash to be able to send IPTABLES scripts to my
firewall interactively. This could make PostgreSQL one of the only database
able to counter attack on the fly during data acquisition.

Also, in order to write fast server-side applications, do not hesitate to try
pgAdmin III from http://www.pgadmin.org. This will give you direct access to
the list of CASTs. pgAdmin III has a large number of very handy features to
write server-side applications.

Cheers,
Jean-Michel
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: lkrubner | last post by:
This might be an idiot question, but how do you group by timestamps by date? I mean, given a large number of timestamps, spanning many months, how do grab them and say how many are from each day?...
0
by: Eugene | last post by:
Hi, I have been battling with this for days now. If you execute the SQL below you will get the following result: 0x3078303030303030, which is incorrect. It looks like the conversion is more...
15
by: Daniel Schuchardt | last post by:
Hi @ all, i'm sure there was a psql-function to transfere my Blob-Data to the server but I can't remember. I have a script like this : UPDATE xy SET z = lo_import('localpath_and_file'); ...
5
by: Robert Schuldenfrei | last post by:
Dear NG, I have not heard from anyone about a good book that deals with the concurrency issue in SQL Server using C#. I have PROMISED Nick I would not use record locking and I have used an old...
2
by: Chumma Dede | last post by:
Hi, I need to code a DLL in .NET which logs the response times for our asp.net multi-tier application. The problem is we need to log the timestamps at multiple stages in a process lifecycle...
4
by: Craig G | last post by:
im not too sure how i should be storing the SQL2000 timestamps basically i return a dataset which is used to populate an editable grid. this dataset contains the timestamp. how should i be...
3
by: Tgone | last post by:
Hello, I need to convert a MySQL date "2007-03-08", into "March 8th, 2007". Normally I would use MySQL to accomplish this task but I have to use PHP. Here's my code: echo date("F jS, Y",...
12
by: Vincent Delporte | last post by:
Hello My site is hosted on a server in the US, hence set up to use the mm/dd/yyyy date format instead of the European dd/mm/yyyy. Also, MySQL stores dates as yyyy-mm-dd, so I need to convert...
6
by: xkenneth | last post by:
All, Just a quick question. I want to be able to have a data structure that organizes data (timestamps I'm working with) sequentially, so that i can easily retrieve the first x amount of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.