Heartbeat.php
authorAlan <alan@roojs.com>
Fri, 18 Aug 2023 06:28:44 +0000 (14:28 +0800)
committerAlan <alan@roojs.com>
Fri, 18 Aug 2023 06:28:44 +0000 (14:28 +0800)
Heartbeat.php [new file with mode: 0644]

diff --git a/Heartbeat.php b/Heartbeat.php
new file mode 100644 (file)
index 0000000..a3f7d4f
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+// check if database is workign - used by nagios checking - to see if server is really up.
+
+require_once 'Pman.php';
+
+class Pman_Core_Heartbeat extends Pman
+{
+    function getAuth()
+    {
+        return true;
+    }
+    
+    function get($req, $opts = array())
+    {
+        $this->post($req);
+        die("POST only");
+    }
+    
+    function post($req)
+    {
+        $this->initErrorHandling();
+        $cd = DB_DataObject::Factory('core_enum');
+        $cd->setFrom(array(
+            'etype' => 'heartbeat',
+            'name' => 'last_update'
+        ));
+        if (!$cd->count()) {
+            $cd->display_name = date("Y-m-d H:i:s");
+            $cd->insert();
+            die("OK");
+        }
+        $cd->find(true);
+        $cc = clone($cd);
+        $cd->display_name = date("Y-m-d H:i:s");
+        $cd->update($cc);
+        die("OK");
+    }
+    
+     
+    function onPearError($err)
+    {
+      //  print_r($err);
+        die("FAILED");
+    }
+    function onException($err)
+    {
+      //  print_r($err);
+        die("FAILED");
+    }
+}
\ No newline at end of file