Zabbix server external scripts » Historie » Version 1
Jeremias Keihsler, 13.01.2017 18:38
| 1 | 1 | Jeremias Keihsler | h1. external Scripts |
|---|---|---|---|
| 2 | |||
| 3 | See also http://lab4.org/wiki/Zabbix_erweitern_mit_External_Checks |
||
| 4 | |||
| 5 | This script is based on https://87.110.183.172/forum/showthread.php?t=22666 |
||
| 6 | <pre><code class="bash"> |
||
| 7 | vim /etc/zabbix/externalscripts/fileage.sh |
||
| 8 | </code></pre> |
||
| 9 | |||
| 10 | <pre><code class="bash"> |
||
| 11 | #!/bin/bash |
||
| 12 | #echo out parameter: |
||
| 13 | #echo $1 $2>/tmp/zabbix_external_script_fileage.log |
||
| 14 | |||
| 15 | |||
| 16 | # Usage instructions: |
||
| 17 | if [ -z "$2" ]; then |
||
| 18 | echo "Usage: " |
||
| 19 | echo " $0 host-IP filename" |
||
| 20 | echo "will tell you the age of the file in seconds, " |
||
| 21 | echo "or -1 if the file does not exist, " |
||
| 22 | echo "or -2 if the OS is not supported" |
||
| 23 | exit |
||
| 24 | fi |
||
| 25 | |||
| 26 | # Test if the file exists: |
||
| 27 | if [ ! -f "$2" ]; then |
||
| 28 | echo -1 |
||
| 29 | exit |
||
| 30 | fi |
||
| 31 | |||
| 32 | # Output the age, but note that the same command cannot be used on Mac and Linux: |
||
| 33 | # Note: On Mac, stat -s filename sts environment variables based on the file's properties. |
||
| 34 | if [ `uname` == 'Darwin' ]; then |
||
| 35 | NOW=`date +%s` |
||
| 36 | eval $(stat -s $2) |
||
| 37 | (( DIFF = (NOW - $st_ctime) )) |
||
| 38 | echo $DIFF; |
||
| 39 | exit |
||
| 40 | fi |
||
| 41 | if [ `uname` == 'Linux' ]; then |
||
| 42 | OLD=`stat -c %Z $2` |
||
| 43 | NOW=`date +%s` |
||
| 44 | (( DIFF = (NOW - OLD) )) |
||
| 45 | echo $DIFF; |
||
| 46 | exit |
||
| 47 | fi |
||
| 48 | |||
| 49 | #echo "Unsupported operating system" |
||
| 50 | echo -2 |
||
| 51 | </code></pre> |