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.
PHP & MYSQL, Logging time a field stays the same
Moderator: General Moderators
Re: PHP & MYSQL, Logging time a field stays the same
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` = 2Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: PHP & MYSQL, Logging time a field stays the same
Thanks a bunch, that's exactly what I was looking for.