# File:    $Id$
# Author:  (c) 2010 Matthew Wall
# map rules from a small nagios installation owned by mwall
#
# i tend to use short, lowercase names for the data sources (in this map file)
# and service names (in my nagios service definitions), then use the
# labels.conf file to provide more user-friendly strings that appear
# in the web pages.

# avoid unuseful timeout and errors 
/output:CHECK_NRPE: Socket timeout/ 
and return ('ignore');
 
/output:NRPE: Unable to read output/ 
and return ('ignore');
 
/output:CRITICAL - Socket timeout after/ 
and return ('ignore');
 
/output:Connection refused by host/ 
and return ('ignore');

/output:CRITICAL - Plugin timed out after/
and return ('ignore');

/output:Error contacting/
and return ('ignore');

/output:SSH OK/
and return ('ignore');

# Service type: ping
#   output:PING OK - Packet loss = 0%, RTA = 0.00 ms
/output:PING.*?(\d+)%.+?([.\d]+)\sms\s*perfdata:rta=([.\d]+)ms;([.\d]+);([.\d]+);([.\d]+)\s+pl=([.\d]+)%;([.\d]+);([.\d]+);([.\d]+)/
and push @s, [ 'loss',
               [ 'losspct', GAUGE, $1 ],
               [ 'losswarn', GAUGE, $8 ],
               [ 'losscrit', GAUGE, $9 ]]
and push @s, [ 'rta',
               [ 'rta', GAUGE, $2/1000 ],
               [ 'rtawarn', GAUGE, $4/1000 ],
               [ 'rtacrit', GAUGE, $5/1000 ] ];

# Service type: single disk
#  output:DISK OK - free space: /tmp 663 MB (90%):
/output:DISK.*free space: (\S+) (\d+) MB \((\d+)\%\)/
and push @s, [ $1,
               [ 'bytesfree', GAUGE, $2*1024**2 ],
               [ 'bytesmax', GAUGE, $3 ? $2*1024**2/$3*100 : 'U' ],
               [ 'pctfree', GAUGE, $3 ] ];

# Service type: all unix-disk
# Note: nagiosplugin requires the inode patch
#   ouput:DISK OK - free space: / 12372 mB (77% inode=96%): /raid 882442 mB (88% inode=91%):
#   perfdata: /=12372mB;14417;15698;96;16019 /raid=882441mB;999780;999780;91;999780
/output:DISK.*inode=/ and do {
  my @_pct = /: (\/.*?) .*?(\d+)% inode=(\d+)%/g;
  while ( my($_d,$_b,$_i) = splice @_pct,0,3 ) {
    my @_s;
    /perfdata:.*$_d=(\d+)\w*?;(\d+);(\d+);(\d+);(\d+)/;
    push @s, [ $_d,
               [ 'used',     GAUGE, $1*1024**2  ],
               [ 'warn',     GAUGE, $2*1024**2  ],
               [ 'crit',     GAUGE, $3*1024**2  ],
               [ 'total',    GAUGE, $5*1024**2  ],
               [ 'blockpct', GAUGE, $_b ],
               [ 'inodepct', GAUGE, $_i ] ];
  }
};

# Service type: unix-dns
#   output:DNS OK - 0.008 seconds response time (test.test.1M IN A192.169.0.47)
#   perfdata:time=8260us;;;0
/output:DNS.*?([.0-9]+) sec/
and push @s, [ 'dns',
               [ 'response',  GAUGE, $1 ] ];

# Service type: unix-imap
#   output:IMAP OK - 0.009 second response time on port 143
/output:IMAP.*?([-.0-9]+) sec/
and push @s, [ 'imap',
               [ 'response', GAUGE, $1 ] ];

# Service type: unix-ldap
#   ouput:LDAP OK - 0.004 seconds response time
#   perfdata:time=3657us;;;0
/output:LDAP.*?([.0-9]+) sec/
and push @s, [ 'ldap',
               [ 'response', GAUGE, $1 ] ];

# Service type: unix-load
#   output: OK - load average: 0.66, 0.70, 0.73
#   perfdata:load1=0;15;30;0 load5=0;10;25;0 load15=0;5;20;0
/output:.*load average: ([.0-9]+), ([.0-9]+), ([.0-9]+)/
and push @s, [ 'load',
               [ 'avg1min',  GAUGE, $1 ],
               [ 'avg5min',  GAUGE, $2 ],
               [ 'avg15min', GAUGE, $3 ] ];

# Service type: unix-mailq
#   output:WARNING: mailq is 5717 (threshold w = 5000)
#   perfdata:unsent=5717;5000;10000;0
/perfdata:unsent=(\d+);(\d+);(\d+);(\d+)/
and push @s, [ 'mailq',
               [ 'size', GAUGE, $1 ],
               [ 'warn', GAUGE, $2 ],
               [ 'crit', GAUGE, $3 ] ];

# Service type: unix-netstat
#   output:OK
#   perfdata:udpInDatagrams=46517147, udpOutDatagrams=46192507, udpInErrors=0, 
#   tcpActiveOpens=1451583, tcpPassiveOpens=1076181, tcpAttemptFails=1909, 
#   tcpEstabResets=5045, tcpCurrEstab=6, tcpOutDataBytes=3162434373, 
#   tcpInDataBytes=1942718261, tcpRetransBytes=215439
/perfdata:.*udpInDatagrams=(\d+), udpOutDatagrams=(\d+), udpInErrors=(\d+), tcpActiveOpens=(\d+), tcpPassiveOpens=(\d+), tcpAttemptFails=(\d+), tcpEstabResets=(\d+), tcpCurrEstab=(\d+), tcpOutDataBytes=(\d+), tcpInDataBytes=(\d+), tcpRetransBytes=(\d+)/
and push @s, [ 'udp',
               [ 'InPkts',  DERIVE, int $1/300 ],
               [ 'OutPkts', DERIVE, int $2/300 ],
               [ 'Errors',  DERIVE, int $3/300 ] ],
             [ 'tcp',
               [ 'ActOpens',    DERIVE, int $4/300    ],
               [ 'PsvOpens',    DERIVE, int $5/300    ],
               [ 'AttmptFails', DERIVE, int $6/300    ],
               [ 'OutBytes',    DERIVE, int $9/300*8  ],
               [ 'InBytes',     DERIVE, int $10/300*8 ] ];

# Service type: unix-ntp
#   output:NTP OK: Offset 0.001083 secs, jitter 14.84 msec, peer is stratum 1
/output:NTP.*Offset ([-.0-9]+).*jitter ([-.0-9]+).*stratum (\d+)/
and push @s, [ 'ntp',
               [ 'offset',  GAUGE, $1      ],
               [ 'jitter',  GAUGE, $2/1000 ],
               [ 'stratum', GAUGE, $3+1    ] ];

# Service type: unix-pop
#   output:POP OK - 0.008 second response time on port 110
/output:POP.*?([.0-9]+) second/
and push @s, [ 'pop3',
               [ 'response', GAUGE, $1 ] ];

# Service type: unix-procs
#   output:PROCS OK: 43 processes
/output:PROCS.*?(\d+) processes\n/
and push @s, [ 'procs',
               [ 'procs', GAUGE, $1 ] ];

# Service type: unix-smtp
#   output:SMTP OK - 0.187 sec. response time
/output:SMTP.*?([-.0-9]+) sec/
and push @s, [ 'smtp',
               [ 'response', GAUGE, $1 ] ];

# Service type: unix-swap
#   output:SWAP OK: 96% free (2616 MB out of 2744 MB)
#   perfdata:swap=2616MB;274;54;0;2744
/perfdata:swap=(\d+)MB;(\d+);(\d+);\d+;(\d+)/
and push @s, [ 'swap',
               [ 'free', GAUGE, $1*1024**2 ],
               [ 'max',  GAUGE, $4*1024**2 ],
               [ 'warn', GAUGE, $2*1024**2 ],
               [ 'crit', GAUGE, $3*1024**2 ] ];

# Service type: unix-users
#   output:USERS OK - 4 users currently logged in
#   perfdata:users=4;5;10;0 
/perfdata:users=(\d+);(\d+);(\d+)/
and push @s, [ 'users',
               [ 'users', GAUGE, $1 ],
               [ 'warn',  GAUGE, $2 ],
               [ 'crit',  GAUGE, $3 ] ];

# Service type: unix-zombies
#   ouput:PROCS OK: 0 processes with STATE = Z
#/output:PROCS.*?(\d+) processes.*Z/
#and push @s, [ 'zombie',
#               [ 'zombies', GAUGE, $1 ] ];

# Service type: unix-www
#   ouput:HTTP OK HTTP/1.1 200 OK - 1456 bytes in 0.003 seconds
/output:HTTP.*?(\d+) byte.*?([.0-9]+) sec/
and push @s, [ 'http',
               [ 'Bps', GAUGE, $1/$2 ] ];

# Service type: unix-tcp
#   output:TCP OK - 0.061 second response time on port 22
#   perfdata:time=0.060777s;0.000000;0.000000;0.000000;10.000000
/output:TCP.*?on port (\d+)\s*perfdata:time=(\d+\.\d+).*(\d+\.\d+)\D*(\d+\.\d+)\D*(\d+\.\d+)\D*(\d+\.\d+)/
and push @s, [ "tcp_$1",
               [ 'connect_time',   GAUGE, $2 ],
               [ 'warning_time',   GAUGE, $3 ],
               [ 'critical_time',  GAUGE, $4 ],
               [ 'socket_timeout', GAUGE, $6 ],
             ];




# oculus mappings
# 26dec09 mwall

# Service type: apcupsd
#   output:Battery Charge: 100.0%
#   perfdata:charge=100.0;50;10
/output:.*Charge.*?([.\d]+)%/
and push @s, [ 'charge',
               [ 'charge', GAUGE, $1 ] ];

# Service type: apcupsd
#   output:OK - Time Left: 42.0 Minutes
#   perfdata:42.0;20;10
#/output:.*Time.*?([.\d]+)\sMinutes/
/perfdata:timeleft=([.\d]+);([.\d]+);([.\d]+)/
and push @s, [ 'time',
               [ 'timeleft', GAUGE, $1 ],
               [ 'warn',  GAUGE, $2 ],
               [ 'crit',  GAUGE, $3 ] ];

# Service type: apcupsd
#   output:OK - Load: 5.2%
#   perfdata:load=3.6;30;40
#/output:.*Load.*?([.\d]+)%/
/perfdata:load=([.\d]+);([.\d]+);([.\d]+)/
and push @s, [ 'load',
               [ 'load', GAUGE, $1 ],
               [ 'warn',  GAUGE, $2 ],
               [ 'crit',  GAUGE, $3 ] ];

# Service type: apcupsd
#   output:OK - Internal Temperature: 25.6 C
#   perfdata:25.6;30;40
#/output:.*Temperature.*?([.\d]+)\sC/
/perfdata:temperature=([.\d]+);([.\d]+);([.\d]+)/
and push @s, [ 'temp',
               [ 'temperature', GAUGE, $1 ],
               [ 'warn',  GAUGE, $2 ],
               [ 'crit',  GAUGE, $3 ] ];

# Service type: unix uptime
#   output:OK - uptime is 36 Days, 2 Hours, 42 Minutes
#   perfdata:
/output:.*uptime is.*?([.\d]+)\sDays/
and push @s, [ 'data',
               [ 'days', GAUGE, $1 ] ]
or (/output:.*uptime is.*?([.\d]+)\sHours/
    and push @s, [ 'data',
               [ 'days', GAUGE, $1/24 ] ])
or (/output:.*uptime is.*?([.\d]+)\sMinutes/
    and push @s, [ 'data',
               [ 'days', GAUGE, $1/1440 ] ]);

# Service type: macosx-ntp
#   output:NTP OK: Offset 0.001083 secs
/output:NTP.*Offset ([-.0-9]+)/
and push @s, [ 'ntp',
               [ 'offset',  GAUGE, $1 ] ];

# Service type: unix-ntp-client
#   output:NTP OK: Offset 0.001083 secs
# perfdata:offset=1032.98;60.00000; 120.00000;
/perfdata: offset=([-.0-9]+)s;(.\d+);(.\d+);/
and push @s, [ 'data',
               [ 'offset',  GAUGE, $1 ],
               [ 'warn',  GAUGE, $2 ],
               [ 'crit', GAUGE, $3 ] ];

# Service type: unix total processes
#   output:OK: Total: 90, Zombie: 0, RSDT: 23
# perfdata:total=90 zombie=0 rsdt=23
/perfdata:total=(\d+) zombie=(\d+) rsdt=(\d+)/
and push @s, [ 'data',
               [ 'total', GAUGE, $1 ],
               [ 'zombie', GAUGE, $2 ],
               [ 'rsdt', GAUGE, $3 ] ];

# Service type: unix cpu
#   output: User: 14%, Nice: 0%, System: 1%, Idle: 83%
# perfdata: user=14.17 nice=0 sys=1.9488 idle=83.87
/perfdata:user=([.\d]+) nice=([.\d]+) sys=([.\d]+) idle=([.\d]+)/
and push @s, [ 'cpu',
               [ 'user', GAUGE, $1 ],
               [ 'nice', GAUGE, $2 ],
               [ 'system', GAUGE, $3 ],
               [ 'idle', GAUGE, $4 ]];

# FIXME: fix the plugin to report warn and crit instead of hardcoding it here
# Service type: unix memory
#   output: Real Free: 25924 kB, Swap Free: 1505472 kb
#   perfdata: total=514560 free=25924 swaptot=1506172 swapfree=1505472
/perfdata:total=([\d]+) free=([\d]+) swaptot=([\d]+) swapfree=([\d]+)/
and push @s, [ 'real',
               [ 'total', GAUGE, $1*1024 ],
               [ 'free', GAUGE, $2*1024 ],
               [ 'used', GAUGE, ($1 - $2)*1024 ],
               [ 'warn', GAUGE, 0.9 * $1*1024 ],
               [ 'crit', GAUGE, 0.95 * $1*1024 ]],
             [ 'swap',
               [ 'total', GAUGE, $3*1024 ],
               [ 'free', GAUGE, $4*1024 ],
               [ 'used', GAUGE, ($3 - $4)*1024 ],
               [ 'warn', GAUGE, 0.9 * $3*1024 ],
               [ 'crit', GAUGE, 0.95 * $3*1024 ]];

# Service type: unix network
#   output: Received 3956221475, Transmitted = 571374458
# perfdata: rbyte=3956221475 rpacket=36097353 rerr=0 rdrop=0 rmult=0 tbyte=571374458 tpacket=62062295 terr=6 tdrop=0 tmult=0
/perfdata:rbyte=([\d]+) rpacket=([\d]+) rerr=([\d]+) rdrop=([\d]+) rmult=([\d]+) tbyte=([\d]+) tpacket=([\d]+) terr=([\d]+) tdrop=([\d]+) tmult=([\d]+)/
and push @s, [ 'data',
               [ 'byte-received', COUNTER, $1 ],
               [ 'byte-transmitted', COUNTER, $6 ],
               [ 'packet-received', COUNTER, $2 ],
               [ 'packet-transmitted', COUNTER, $7 ],
               [ 'error-received', COUNTER, $3 ],
               [ 'error-transmitted', COUNTER, $8 ],
               [ 'drop-received', COUNTER, $4 ],
               [ 'drop-transmitted', COUNTER, $9 ],
               [ 'multi-received', COUNTER, $5 ],
               [ 'multi-transmitted', COUNTER, $10 ]];

# Service type: smartmon temperature
#   output: OK - /dev/hda
# perfdata: Temperature_Celsius_raw=35;40;45;;
(/perfdata:Temperature_Celsius_raw=([\d]+);([\d]*);([\d]*).*Temperature_Celsius_min=([\d]+);([\d]*);([\d]*).*Temperature_Celsius_max=([\d]+);([\d]*);([\d]*)/
and push @s, [ 'temp',
               [ 'temperature', GAUGE, $1 ],
               [ 'warn', GAUGE, $2 ],
               [ 'crit', GAUGE, $3 ],
               [ 'lifetime-min', GAUGE, $4 ],
               [ 'lifetime-max', GAUGE, $7 ]])
or
(/perfdata:Temperature_Celsius_raw=([\d]+);([\d]*);([\d]*)/
and push @s, [ 'temp',
               [ 'temperature', GAUGE, $1 ],
               [ 'warn', GAUGE, $2 ],
               [ 'crit', GAUGE, $3 ]]);

# FIXME: this is hard-coded for dual cpus on data00
# Service type: sensors cpu and motherboard temperatures
#   output: MOTHERBOARD = 28.0C, CPU0 = 41.5C, CPU1 = 42.5C
#/output:MOTHERBOARD = ([.\d]+)C, CPU0 = ([.\d]+)C, CPU1 = ([.\d]+)C/
/perfdata:MOTHERBOARD=([.\d]+);([.\d]+);([.\d]+) CPU0=([.\d]+);([.\d]+);([.\d]+) CPU1=([.\d]+);([.\d]+);([.\d]+)/
and push @s, [ 'temp',
               [ 'motherboard', GAUGE, $1 ],
               [ 'cpu0', GAUGE, $4 ],
               [ 'cpu1', GAUGE, $7 ],
               [ 'warn', GAUGE, $2 ],
               [ 'crit', GAUGE, $3 ] ];

# FIXME: this is hard-coded for 3 fans
# Service type: sensors fan speeds
#   output: OK - fan1 = 4787 RPM, fan2 = 4560 RPM, fan3 = 3426 RPM
# perfdata: fan1=4787;; fan2=4560;; fan3=3426;;
/perfdata:fan1=([.\d]+);([.\d]+);([.\d]+) fan2=([.\d]+);([.\d]+);([.\d]+) fan3=([.\d]+);([.\d]+);([.\d]+)/
and push @s, [ 'fans',
               [ 'fan1', GAUGE, $1 ],
               [ 'fan2', GAUGE, $4 ],
               [ 'fan3', GAUGE, $7 ],
               [ 'warn', GAUGE, $2 ],
               [ 'crit', GAUGE, $3 ] ];

# Service type: openvpn
#   output:
# perfdata:
/output:CHECKOPENVPN OK:\s+(\d+) connected/
and push @s, [ 'vpn',
               [ 'users', GAUGE, $1 ] ];
