User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:public:apcupsd-notifications [2018/07/25 22:11]
robertguerra created
en:public:apcupsd-notifications [2019/01/25 21:11] (current)
robertguerra
Line 1: Line 1:
-This example uses the feature create_notification to send an **error** message with the Battery ​(apcupsd) status.+====== APCUPS ​Battery ​notification======
  
-1. Edit the  **/etc/apcupsd/changeme** file so it is as follows:+In this tutorial, we use the function ''​create_notification'',​ which sends the message according to the settings in the administration //Foris//, section //Maintenance//
  
-    #!/bin/sh +<WRAP center important 60%> 
-    ​MSG="​$HOSTNAME UPS battery needs changing NOW. \\n \\n $(apcaccess status)"​ +Tutorial assumes, you have installed the **apcupsd** package ​ 
-    /usr/​bin/​create_notification -s error "​${MSG}"​ +</WRAP>
-    /​usr/​bin/​notifier +
-    exit 0+
  
-2. Edit the  **/​etc/​apcupsd/​commfailure** file so it is as follows: 
  
-    #!/bin/sh  +**1)** in replace the file ''​/etc/apcupsd/changeme''​ with the following:
-    MSG="​$HOSTNAME Communications with UPS lost. \\n \\n $(apcaccess status)+
-    ​/usr/bin/create_notification -s error "​${MSG}"​ +
-    /​usr/​bin/​notifier +
-    exit 0+
  
-3Edit the  **/​etc/​apcupsd/​commok** file so it is as follows:+<​code>​ 
 +#!/bin/sh 
 +. /​etc/​apcupsd/​apcupsd_mail.conf
  
-    #!/bin/sh +MSG="$HOSTNAME ​UPS battery needs changing NOW.
-    message="$(echo -e "​${common_name} Communications with UPS restored\\n \\n $(apcaccess status)"​ +
-    /​usr/​bin/​create_notification -s error "​${message}"​ +
-    /​usr/​bin/​notifier +
-    exit 0+
  
-4. Edit the  **/​etc/​apcupsd/​offbattery** file so it is as follows:+"
  
-    #!/bin/sh +OUTPUT="${MSG} $(apcaccess status)"​ 
-    MSG="$HOSTNAME Communications with UPS restored. \\n \\n $(apcaccess status)"​ +/​usr/​bin/​create_notification -s error "${OUTPUT}" 
-    /​usr/​bin/​create_notification -s error "${MSG}" +/​usr/​bin/​notifier
-    /​usr/​bin/​notifier +
-    exit 0+
  
-4Edit the  **/​etc/​apcupsd/​onbattery** file so it is as follows:+exit 0 
 +</​code>​ 
 + 
 +**2)** in replace the file ''/​etc/​apcupsd/​commfailure''​ with the following:​ 
 + 
 +<​code>​ 
 +#!/bin/sh 
 +/​etc/​apcupsd/​apcupsd_mail.conf 
 + 
 +MSG="​$HOSTNAME Communications with UPS lost. 
 + 
 +
 + 
 +OUTPUT="​${MSG} $(apcaccess status)"​ 
 +/​usr/​bin/​create_notification -s error "​${OUTPUT}"​ 
 +/​usr/​bin/​notifier 
 +exit 0 
 + 
 +</​code>​ 
 + 
 +**3)** in replace ​the file ''/​etc/​apcupsd/​commok''​ with the following:​ 
 + 
 +<​code>​ 
 +#!/bin/sh 
 +. /​etc/​apcupsd/​apcupsd_mail.conf 
 + 
 +MSG="​$HOSTNAME Communications with UPS restored.  
 + 
 +
 + 
 +OUTPUT="​${MSG} $(apcaccess status)"​ 
 +/​usr/​bin/​create_notification -s error "​${OUTPUT}"​ 
 +/​usr/​bin/​notifier 
 + 
 + 
 +exit 0 
 +</​code>​ 
 + 
 +**4)** in replace the file ''​/​etc/​apcupsd/​offbattery''​ with the following:​ 
 + 
 +<​code>​ 
 +#!/bin/sh 
 +. /​etc/​apcupsd/​apcupsd_mail.conf 
 + 
 +MSG="​$HOSTNAME Communications with UPS restored. 
 + 
 +
 + 
 +OUTPUT="​${MSG} $(apcaccess status)"​ 
 +/​usr/​bin/​create_notification -s error "​${OUTPUT}"​ 
 +/​usr/​bin/​notifier 
 + 
 +exit 0 
 +</​code>​ 
 + 
 +**5)** in replace the file ''/​etc/​apcupsd/​onbattery''​ with the following: 
 + 
 +<​code>​ 
 +#!/bin/sh 
 +. /​etc/​apcupsd/​apcupsd_mail.conf 
 + 
 +MSG="​$HOSTNAME Power Failure !!! 
 + 
 +
 + 
 +OUTPUT="​${MSG} $(apcaccess status)"​ 
 +/​usr/​bin/​create_notification -s error "​${OUTPUT}"​ 
 +/​usr/​bin/​notifier 
 + 
 +exit 0 
 +</​code>​ 
 + 
 + 
 +**6)** restart APCUPSD 
 + 
 +''/​etc/​init.d/​apcupsd restart''​
  
-    #!/bin/sh 
-    MSG="​$HOSTNAME Power Failure!!! \\n \\n $(apcaccess status)"​ 
-    /​usr/​bin/​create_notification -s error "​${MSG}"​ 
-    /​usr/​bin/​notifier 
-    exit 0