#!/usr/bin/perl
# -*- perl -*-

# Copyright (C) 2015 Pirx Developers - https://pirx.dev/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

=head1 NAME

hq_uptime - Munin plugin to monitor system uptime.

=head1 APPLICABLE SYSTEMS

Linux systems.

=head1 CONFIGURATION

Not needed.

=head1 VERSION

  20151016

=head1 MAGIC MARKERS

  #%# family=manual
  #%# capabilities=autoconf

=head1 BUGS

None.

=head1 AUTHOR

Pirx Developers - https://pirx.dev/

=head1 LICENSE

GPLv3

=cut

use strict;
use warnings;

# Handle autoconf
if(defined($ARGV[0]) and $ARGV[0] eq 'autoconf') {
  print("yes\n");
  exit(0);
}

# Get current uptime
my $uptime = `cut -d' ' -f 1 /proc/uptime 2>/dev/null`;
chomp($uptime);
$uptime = $uptime / 86400;
 
# Handle config
if(defined($ARGV[0]) and $ARGV[0] eq 'config') {
  print <<EOF;
graph_title System uptime
graph_args --base 1000 --lower-limit 0
graph_scale no
graph_vlabel days
graph_category system

uptime.label Uptime
uptime.type GAUGE
uptime.min 0
uptime.draw AREA
uptime.colour 00d000
EOF
  exit(0);
}

printf("uptime.value %.2f\n", $uptime);

exit(0);
