Page 1 of 1

PHP & MYSQL, Logging time a field stays the same

Posted: Wed Mar 09, 2011 10:27 am
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.

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

Posted: Thu Mar 10, 2011 9:57 am
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

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

Posted: Mon Mar 14, 2011 11:12 am
by dtunget
Thanks a bunch, that's exactly what I was looking for.