Inc. # All rights reserved. #------------------------------------------------------------------ ### The following EEM environment variables are used: ### ### _tm_fsys_usage_cron (optional) - cron specification which will be used ### in the event register command. If ### unspecified the policy will trigger ### once per minute. ### Example: _tm_fsys_usage_cron 0-59/1 0-23/1 * * 0-7 ### ### _tm_fsys_usage_percent (optional) - disk usage percentage thesholds for ### systems or specific prefixes. If disk ### usage percentage exceeds a given ### percentage then a warning will be ### displayed. ### If _tm_fsys_usage_percent is not set ### it defaults to 80% for all systems. ### Example: _tm_fsys_usage_percent nvram:25 disk2:5 ### ### _tm_fsys_usage_freebytes (optional)- Free byte threshold for systems or ### specific prefixes. If free space ### falls below a given value then a ### warning will be displayed: ### Example: _tm_fsys_usage_freebytes disk2:98000000 ### ### _tm_fsys_usage_debug (optional) - When set to 1, disk usage information ### is displayed for all entries in the ### system. namespace import ::cisco::eem::* namespace import ::cisco::lib::* # 1. check if all the env variables we need exist and if not assign defaults if {![info exists _tm_fsys_usage_percent]} { set _tm_fsys_usage_percent "" set _tm_fsys_use_default_percent 80 } if {![info exists _tm_fsys_usage_freebytes]} { set _tm_fsys_usage_freebytes "" } if {![info exists _tm_fsys_usage_debug]} { set _tm_fsys_usage_debug 0 } # 2. Gather file system information from CLI if [catch {cli_open} result] { error $result $errorInfo } else { array set cli1 $result } if [catch {cli_exec $cli1(fd) "en"} result] { error $result $errorInfo } if [catch {cli_exec $cli1(fd) "show file sys"} cli_show_filesys] { error $cli_show_filesys $errorInfo } if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] { error $result $errorInfo } # 3. Loop through each file system entry returned foreach l [split $cli_show_filesys \n] { set x "" set m [regexp {([_A-Za-z0-9]*:)} $l match fprefix] if {$m == 1} { # Matched a file system in show file sys output set m [regexp {\s*([0-9]+)\s*([0-9]+)\s*([a-zA-Z0-9]*)} $l match dtot dfree ftype] if {$m == 1} { # File system is in use, obtain size, and free info. if {$dtot <= 0} { continue; } set calc1 [expr 1.0 * $dfree / $dtot * 100] set perc [expr 100 - $calc1] if {$_tm_fsys_usage_debug == 1} { action_syslog priority info msg "$fprefix usage: [format %.0f $perc]% size: $dtot, free: $dfree type: $ftype" } set prefixpattern "($fprefix\[0-9\]+)" set typepattern "($ftype:\[0-9\]+)" # Check free percents against threshold values. if ([info exists _tm_fsys_use_default_percent]) { set m 1 set entry "all:$_tm_fsys_use_default_percent" } else { # Check against prefix name. set m [regexp $prefixpattern $_tm_fsys_usage_percent entry] if {$m != 1} { # Prefix not found, so check file system type. set m [regexp $typepattern $_tm_fsys_usage_percent entry] } } if {$m == 1} { # Matched a threshold entry for this file system. set thresh [lindex [split $entry :] 1] if [info exists thresh] { if [expr $perc > $thresh] { action_syslog priority info msg "Warning $fprefix utilization ([format %.0f $perc]%) exceeds threshold ([format %.0f $thresh]%); free space $dfree" } } } # Now check against free bytes. set m [regexp $prefixpattern $_tm_fsys_usage_freebytes entry] if {$m != 1} { # Prefix not found, so check system type. set m [regexp $typepattern $_tm_fsys_usage_freebytes entry] } if {$m == 1} { # Matched a freebytes entry for this file system. set freebytes [lindex [split $entry :] 1] if [info exists freebytes] { if [expr $freebytes > $dfree] { action_syslog priority info msg "Warning $fprefix free bytes has fallen below theshold: free $dfree : threshold $freebytes" } } } } } }