PHP & MYSQL, Logging time a field stays the same

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dtunget
Forum Newbie
Posts: 2
Joined: Wed Mar 09, 2011 10:19 am

PHP & MYSQL, Logging time a field stays the same

Post by dtunget »

I'm using a mysql database to hold data about network switch ports. The port status is collected and logged as a 1,2,3 for up/down/admin down. What I need to do is develop some php (or possibly perl) code to check the database for a ports status and log when one starts showing down, and then I THINK have a field that increments each time the port is down (it's a daily scan). This way I can set the ports for decomission if they're down for say 10 consecutive days. I'd also need to put in some code to remove the interface from the "down" table if it comes up or goes into admin down.

Any ideas on how to do the "consecutive days down" piece? I think I have a handle on the rest of it but I've never written anything that kind of logs a field's status this way.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP & MYSQL, Logging time a field stays the same

Post by pickle »

Add a "consecutive_days_down" column that defaults to 0. In your daily scan, run a query like this:

Code: Select all

UPDATE
  `ports`
SET
  `consecutive_days_down` = `consecutive_days_down` + 1
WHERE
  `status` = 2
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
dtunget
Forum Newbie
Posts: 2
Joined: Wed Mar 09, 2011 10:19 am

Re: PHP & MYSQL, Logging time a field stays the same

Post by dtunget »

Thanks a bunch, that's exactly what I was looking for.
Post Reply