Nieuws:

Welkom, Gast. Alsjeblieft inloggen of registreren.
Heb je de activerings-mail niet ontvangen?

Auteur Topic: Fout CPU Temp Nagios  (gelezen 2340 keer)

Offline Smitty

  • Lid
Fout CPU Temp Nagios
« Gepost op: 2015/10/14, 11:06:58 »
Zojuist heb ik Nagios geïnstalleerd en wil de CPU temp van mijn laptop bekijken. Ik heb daarvoor de check_temp.sh geplaatst in usr/local/nagios/libexec. Daarnaast heb ik het volgende geplaatst bij: /usr/local/nagios/etc/servers/clients.cfg:

define service {
               use                                        generic-service
               host_name                         (de gegeven naam)
               service_description         CPU TEMP
               check_command              check_temp!75!85!"CPU ., Core
               notifications_enabled    0
               }

Dat levert vervolgens de Syntax error op zoals te zien is in de bijlage. Wat is het probleem?

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #1 Gepost op: 2015/10/14, 11:10:43 »
Dit is de inhoud van de Check_temp.sh:

#!/bin/bash

################################################################################
#                                                                              #
#  Copyright (C) 2011 Jack-Benny Persson <jake@cyberinfo.se>                   #
#                                                                              #
#   This program is free software; you can redistribute it and/or modify       #
#   it under the terms of the GNU General Public License as published by       #
#   the Free Software Foundation; either version 2 of the License, or          #
#   (at your option) any later version.                                        #
#                                                                              #
#   This program is distributed in the hope that it will be useful,            #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of             #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              #
#   GNU General Public License for more details.                               #
#                                                                              #
#   You should have received a copy of the GNU General Public License          #
#   along with this program; if not, write to the Free Software                #
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  #
#                                                                              #
################################################################################

###############################################################################
#                                                                             #
# Nagios plugin to monitor CPU and M/B temperature with sensors.              #
# Written in Bash (and uses sed & awk).                                       #
# Latest version of check_temp can be found at the below URL:                 #
# https://github.com/jackbenny/check_temp                                     #
#                                                                             #
# If you are having problems getting it to work, check the instructions in    #
# the README first. It walks you though install lm-sensors and getting it to  #
# display sensor data.                                                        #
#                                                                             #
###############################################################################

VERSION="Version 0.8"
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)"

# Sensor program
SENSORPROG=/usr/bin/sensors

# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

shopt -s extglob

#### Functions ####

# Print version information
print_version()
{
printf "\n\n$0 - $VERSION\n"
}

#Print help information
print_help()
{
print_version
printf "$AUTHOR\n"
printf "Monitor temperature with the use of sensors\n"
/bin/cat <<EOT

Options:
-h
   Print detailed help screen
-V
   Print version information
-v
   Verbose output

--sensor WORD
   Set what to monitor, for example CPU or MB (or M/B). Check sensors for the
   correct word. Default is CPU.
-w INTEGER
   Exit with WARNING status if above INTEGER degres
-c INTEGER
   Exit with CRITICAL status if above INTEGER degres
EOT
}


###### MAIN ########

# Warning threshold
thresh_warn=
# Critical threshold
thresh_crit=
# Hardware to monitor
sensor=CPU

# See if we have sensors program installed and can execute it
if [[ ! -x "$SENSORPROG" ]]; then
printf "\nIt appears you don't have sensors installed in $SENSORPROG\n"
exit $STATE_UNKOWN
fi

# Parse command line options
while [[ -n "$1" ]]; do
   case "$1" in

       -h | --help)
           print_help
           exit $STATE_OK
           ;;

       -V | --version)
           print_version
           exit $STATE_OK
           ;;

       -v | --verbose)
           : $(( verbosity++ ))
           shift
           ;;

       -w | --warning)
           if [[ -z "$2" ]]; then
               # Threshold not provided
               printf "\nOption $1 requires an argument"
               print_help
               exit $STATE_UNKNOWN
            elif [[ "$2" = +([0-9]) ]]; then
               # Threshold is an integer
               thresh=$2
            else
               # Threshold is not an integer
               printf "\nThreshold must be an integer"
               print_help
               exit $STATE_UNKNOWN
           fi
           thresh_warn=$thresh
   shift 2
           ;;

       -c | --critical)
           if [[ -z "$2" ]]; then
               # Threshold not provided
               printf "\nOption '$1' requires an argument"
               print_help
               exit $STATE_UNKNOWN
            elif [[ "$2" = +([0-9]) ]]; then
               # Threshold is an integer
               thresh=$2
            else
               # Threshold is not an integer
               printf "\nThreshold must be an integer"
               print_help
               exit $STATE_UNKNOWN
           fi
           thresh_crit=$thresh
   shift 2
           ;;

       -\?)
           print_help
           exit $STATE_OK
           ;;

       --sensor)
   if [[ -z "$2" ]]; then
printf "\nOption $1 requires an argument"
print_help
exit $STATE_UNKNOWN
   fi
sensor=$2
           shift 2
           ;;

       *)
           printf "\nInvalid option '$1'"
           print_help
           exit $STATE_UNKNOWN
           ;;
   esac
done


# Check if a sensor were specified
if [[ -z "$sensor" ]]; then
# No sensor to monitor were specified
printf "\nNo sensor specified"
print_help
exit $STATE_UNKNOWN
fi


#Get the temperature
TEMP=`${SENSORPROG} | grep "$sensor" | cut -d+ -f2 | cut -c1-2 | head -n1`
#Old way - Get the temperature
#TEMP=`${SENSORPROG} | grep "$sensor" | awk '{print $3}' | cut -c2-3 | head -n1`


# Check if the thresholds have been set correctly
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
# One or both thresholds were not specified
printf "\nThreshold not set"
print_help
exit $STATE_UNKNOWN
  elif [[ "$thresh_crit" -lt "$thresh_warn" ]]; then
# The warning threshold must be lower than the critical threshold
printf "\nWarning temperature should be lower than critical"
print_help
exit $STATE_UNKNOWN
fi


# Verbose output
if [[ "$verbosity" -ge 1 ]]; then
   /bin/cat <<__EOT
Debugging information:
  Warning threshold: $thresh_warn
  Critical threshold: $thresh_crit
  Verbosity level: $verbosity
  Current $sensor temperature: $TEMP
__EOT
printf "\n  Temperature lines directly from sensors:\n"
${SENSORPROG}
printf "\n\n"
fi

# Get performance data for Nagios "Performance Data" field
PERFDATA=`${SENSORPROG} | grep "$sensor" | head -n1`


# And finally check the temperature against our thresholds
if [[ "$TEMP" != +([0-9]) ]]; then
# Temperature not found for that sensor
printf "No data found for that sensor ($sensor)\n"
exit $STATE_UNKNOWN

  elif [[ "$TEMP" -gt "$thresh_crit" ]]; then
# Temperature is above critical threshold
echo "$sensor CRITICAL - Temperature is $TEMP | $PERFDATA"
exit $STATE_CRITICAL

  elif [[ "$TEMP" -gt "$thresh_warn" ]]; then
# Temperature is above warning threshold
echo "$sensor WARNING - Temperature is $TEMP | $PERFDATA"
exit $STATE_WARNING

  else
# Temperature is ok
echo "$sensor OK - Temperature is $TEMP | $PERFDATA"
exit $STATE_OK
fi
exit 3
« Laatst bewerkt op: 2015/10/22, 11:43:45 door TopGear »

Frederik

  • Gast
Re: Fout CPU Temp Nagios
« Reactie #2 Gepost op: 2015/10/14, 13:05:51 »
Een syntax error wordt veroorzaakt door een fout of fouten in de geschreven programmeer code. Kun je zelf niks aan doen, behalve de maker van het programma in kennis stellen van de fout en laten corrigeren. Overigens kun je de temperatuur van de processor gewoon aflezen als je het BIOS opstart.

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #3 Gepost op: 2015/10/14, 13:55:36 »
Klopt, maar het gaat om de Windows CPU temp. Dit is voor een schoolproject en dus is het op deze manier wel noodzakelijk. Ik heb aardig wat Google zoekwerk achter de rug.. Helaas zonder resultaat.

Frederik

  • Gast
Re: Fout CPU Temp Nagios
« Reactie #4 Gepost op: 2015/10/14, 14:04:39 »
Windows CPU? die kun je aflezen (en nog veel meer) met het programma Speccy:
https://www.piriform.com/speccy

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #5 Gepost op: 2015/10/14, 14:16:44 »
Ik ken het programma. Inderdaad een mooi programma. Maar het is de bedoeling dat het afgelezen wordt via Nagios.

Offline Anco

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #6 Gepost op: 2015/10/14, 18:20:30 »
Neem aan dat nagios check_temp!75!85!"CPU ., Core uitvoert? wat doet het zelf als je in terminal dat uitvoert?
Linux user #485563

Offline Moob

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #7 Gepost op: 2015/10/14, 19:07:30 »
De foutmelding zegt het eigenlijk al 'Unterminated quoted string' je mist dus ergens een " of een '

In de code die je toont staat
check_temp!75!85!"CPU ., Corehier staat maar 1x een " , wat gebeurt er als je die weghaald ?

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #8 Gepost op: 2015/10/15, 10:02:46 »
Helaas heeft dat niet het gewenste effect en geeft hij nu de error zoals te zien is in de bijlage. Als ik het dus goed begrijp kijkt hij nu naar de check_temp.pl?

Offline Johan van Dijk

  • Administrator
    • johanvandijk
Re: Fout CPU Temp Nagios
« Reactie #9 Gepost op: 2015/10/16, 08:32:41 »
Nu kan hij het check_temp.pl bestand niet vinden. En dat is niet zo gek, want het bestand dat je gepost hebt is een .sh bestand...

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #10 Gepost op: 2015/10/18, 12:30:37 »
Klopt, maar zoals te zien is in de bijgevoegde afbeelding, heb ik de file wel op de juiste plaats staan..

Offline Moob

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #11 Gepost op: 2015/10/18, 13:24:26 »
Controleer de rechten eens van jou zelfgemaakte scripts. In de schermafbeelding is de te zien dat de rechten afwijken van jou scripts en de al aanwezig nagios scripts.

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #12 Gepost op: 2015/10/21, 09:30:54 »
Ik heb de rechten aangepast en net zo gedaan als de andere bestanden. Helaas heeft dat niet het gewenste effect.

Offline Henkp

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #13 Gepost op: 2015/10/21, 16:02:41 »
Mogelijk heb je wat aan het onderstaande,

inxi -pFxz

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #14 Gepost op: 2015/10/22, 09:49:39 »
Wat is precies de bedoeling dat ik met die code doe? Moet ik die uitvoeren, ergens plaatsen?

Offline Henkp

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #15 Gepost op: 2015/10/22, 12:01:20 »
Wat is precies de bedoeling dat ik met die code doe? Moet ik die uitvoeren, ergens plaatsen?

Je moet niets.
Maar je mag hem in je terminal in geven. En dan zie je je tegelijk je CPU en Moederbord temp in staan.  =D

Offline Johan van Dijk

  • Administrator
    • johanvandijk
Re: Fout CPU Temp Nagios
« Reactie #16 Gepost op: 2015/10/23, 08:54:28 »
Dat is op zich wel een handig commando, alleen heb je er in Nagios niks aan ;)

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #17 Gepost op: 2015/10/26, 14:22:35 »
Bedankt voor je reactie Henkp, maar het is inderdaad niet iets waar ik wat aan heb ;-)

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #18 Gepost op: 2015/11/03, 11:42:37 »
Als iemand nog opties heeft hoor ik die graag.

Offline Smitty

  • Lid
Re: Fout CPU Temp Nagios
« Reactie #19 Gepost op: 2015/11/19, 12:34:41 »
Niemand meer?

Frederik

  • Gast
Re: Fout CPU Temp Nagios
« Reactie #20 Gepost op: 2015/11/19, 20:10:23 »
Helaas niet. Ik heb het programma zojuist geïnstalleerd en het enig wat ik te zien krijg is 'loading'.
Als ik dan na een paar minuten op die melding klik zegt ie 'error' en dat is het dan.