Compare commits
No commits in common. "8e32e01c20f9723b3574ba5b351ed489d6d529d7" and "15097dcba41702683bc1158c85bd664bcec31047" have entirely different histories.
8e32e01c20
...
15097dcba4
150
src/pgmon.py
150
src/pgmon.py
@ -24,10 +24,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
|
|||||||
from http.server import ThreadingHTTPServer
|
from http.server import ThreadingHTTPServer
|
||||||
from urllib.parse import urlparse, parse_qs
|
from urllib.parse import urlparse, parse_qs
|
||||||
|
|
||||||
import requests
|
VERSION = "1.0.2"
|
||||||
import re
|
|
||||||
|
|
||||||
VERSION = "1.0.3"
|
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
config = {}
|
config = {}
|
||||||
@ -46,12 +43,6 @@ cluster_version = None
|
|||||||
cluster_version_next_check = None
|
cluster_version_next_check = None
|
||||||
cluster_version_lock = Lock()
|
cluster_version_lock = Lock()
|
||||||
|
|
||||||
# PostgreSQL latest version information
|
|
||||||
latest_version = None
|
|
||||||
latest_version_next_check = None
|
|
||||||
latest_version_lock = Lock()
|
|
||||||
release_supported = None
|
|
||||||
|
|
||||||
# Running state (used to gracefully shut down)
|
# Running state (used to gracefully shut down)
|
||||||
running = True
|
running = True
|
||||||
|
|
||||||
@ -92,10 +83,6 @@ class MetricVersionError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LatestVersionCheckError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# Default config settings
|
# Default config settings
|
||||||
default_config = {
|
default_config = {
|
||||||
# The address the agent binds to
|
# The address the agent binds to
|
||||||
@ -129,8 +116,6 @@ default_config = {
|
|||||||
"reconnect_cooldown": 30,
|
"reconnect_cooldown": 30,
|
||||||
# How often to check the version of PostgreSQL (seconds)
|
# How often to check the version of PostgreSQL (seconds)
|
||||||
"version_check_period": 300,
|
"version_check_period": 300,
|
||||||
# How often to check the latest supported version of PostgreSQL (seconds)
|
|
||||||
"latest_version_check_period": 86400,
|
|
||||||
# Metrics
|
# Metrics
|
||||||
"metrics": {},
|
"metrics": {},
|
||||||
}
|
}
|
||||||
@ -497,127 +482,6 @@ def get_cluster_version():
|
|||||||
return cluster_version
|
return cluster_version
|
||||||
|
|
||||||
|
|
||||||
def version_num_to_release(version_num):
|
|
||||||
"""
|
|
||||||
Extract the revease from a version_num.
|
|
||||||
|
|
||||||
In other words, this converts things like:
|
|
||||||
90603 => 9.6
|
|
||||||
130010 => 13
|
|
||||||
"""
|
|
||||||
if version_num // 10000 < 10:
|
|
||||||
return version_num // 10000 + (version_num % 10000 // 100 / 10)
|
|
||||||
else:
|
|
||||||
return version_num // 10000
|
|
||||||
|
|
||||||
|
|
||||||
def parse_version_rss(raw_rss, release):
|
|
||||||
"""
|
|
||||||
Parse the raw RSS from the versions.rss feed to extract the latest version of
|
|
||||||
PostgreSQL that's availabe for the cluster being monitored.
|
|
||||||
|
|
||||||
This sets these global variables:
|
|
||||||
latest_version
|
|
||||||
latest_version_next_check
|
|
||||||
release_supported
|
|
||||||
|
|
||||||
It is expected that the caller already holds the latest_version_lock lock.
|
|
||||||
|
|
||||||
params:
|
|
||||||
raw_rss: The raw rss text from versions.rss
|
|
||||||
release: The PostgreSQL release we care about (ex: 9.2, 14)
|
|
||||||
"""
|
|
||||||
global latest_version
|
|
||||||
global latest_version_next_check
|
|
||||||
global release_supported
|
|
||||||
|
|
||||||
# Regular expressions for parsing the RSS document
|
|
||||||
version_line = re.compile(
|
|
||||||
r".*?([0-9][0-9.]+) is the latest release in the {} series.*".format(release)
|
|
||||||
)
|
|
||||||
unsupported_line = re.compile(r"^This version is unsupported")
|
|
||||||
|
|
||||||
# Loop through the RSS until we find the current release
|
|
||||||
release_found = False
|
|
||||||
for line in raw_rss.splitlines():
|
|
||||||
m = version_line.match(line)
|
|
||||||
if m:
|
|
||||||
# Note that we found the version we were looking for
|
|
||||||
release_found = True
|
|
||||||
|
|
||||||
# Convert the version to version_num format
|
|
||||||
version = m.group(1)
|
|
||||||
parts = list(map(int, version.split(".")))
|
|
||||||
if parts[0] < 10:
|
|
||||||
latest_version = int(
|
|
||||||
"{}{:02}{:02}".format(parts[0], parts[1], parts[2])
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
latest_version = int("{}00{:02}".format(parts[0], parts[1]))
|
|
||||||
elif release_found:
|
|
||||||
# The next line after the version tells if the version is supported
|
|
||||||
if unsupported_line.match(line):
|
|
||||||
release_supported = False
|
|
||||||
else:
|
|
||||||
release_supported = True
|
|
||||||
break
|
|
||||||
|
|
||||||
# Make sure we actually found it
|
|
||||||
if not release_found:
|
|
||||||
raise LatestVersionCheckError("Current release ({}) not found".format(release))
|
|
||||||
|
|
||||||
log.info(
|
|
||||||
"Got latest PostgreSQL version: {} supported={}".format(
|
|
||||||
latest_version, release_supported
|
|
||||||
)
|
|
||||||
)
|
|
||||||
log.debug(
|
|
||||||
"Next latest PostgreSQL version check will be after: {}".format(
|
|
||||||
latest_version_next_check
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_latest_version():
|
|
||||||
"""
|
|
||||||
Get the latest supported version of the major PostgreSQL release running on the server being monitored.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# If we don't know the latest version or it's past the recheck time, get the
|
|
||||||
# version from the PostgreSQL RSS feed. Only one thread needs to do this, so
|
|
||||||
# they all try to grab the lock, and then make sure nobody else beat them to it.
|
|
||||||
if (
|
|
||||||
latest_version is None
|
|
||||||
or latest_version_next_check is None
|
|
||||||
or latest_version_next_check < datetime.now()
|
|
||||||
):
|
|
||||||
# Note: we get the cluster version here before grabbing the latest_version_lock
|
|
||||||
# lock so it's not held while trying to talk with the DB.
|
|
||||||
release = version_num_to_release(get_cluster_version())
|
|
||||||
|
|
||||||
with latest_version_lock:
|
|
||||||
# Only check if nobody already got the version before us
|
|
||||||
if (
|
|
||||||
latest_version is None
|
|
||||||
or latest_version_next_check is None
|
|
||||||
or latest_version_next_check < datetime.now()
|
|
||||||
):
|
|
||||||
log.info("Checking latest PostgreSQL version")
|
|
||||||
latest_version_next_check = datetime.now() + timedelta(
|
|
||||||
seconds=int(config["latest_version_check_period"])
|
|
||||||
)
|
|
||||||
|
|
||||||
# Grab the RSS feed
|
|
||||||
raw_rss = requests.get("https://www.postgresql.org/versions.rss")
|
|
||||||
if raw_rss.status_code != 200:
|
|
||||||
raise LatestVersionCheckError("code={}".format(r.status_code))
|
|
||||||
|
|
||||||
# Parse the RSS body and set global variables
|
|
||||||
parse_version_rss(raw_rss.text, release)
|
|
||||||
|
|
||||||
return latest_version
|
|
||||||
|
|
||||||
|
|
||||||
def sample_metric(dbname, metric_name, args, retry=True):
|
def sample_metric(dbname, metric_name, args, retry=True):
|
||||||
"""
|
"""
|
||||||
Run the appropriate query for the named metric against the specified database
|
Run the appropriate query for the named metric against the specified database
|
||||||
@ -699,18 +563,6 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
|||||||
if metric_name == "agent_version":
|
if metric_name == "agent_version":
|
||||||
self._reply(200, VERSION)
|
self._reply(200, VERSION)
|
||||||
return
|
return
|
||||||
elif metric_name == "latest_version_info":
|
|
||||||
try:
|
|
||||||
get_latest_version()
|
|
||||||
self._reply(
|
|
||||||
200,
|
|
||||||
json.dumps(
|
|
||||||
{"latest": latest_version, "supported": 1 if release_supported else 0}
|
|
||||||
),
|
|
||||||
)
|
|
||||||
except LatestVersionCheckError as e:
|
|
||||||
log.error("Failed to retrieve latest version information: {}".format(e))
|
|
||||||
self._reply(503, "Failed to retrieve latest version info")
|
|
||||||
|
|
||||||
# Note: parse_qs returns the values as a list. Since we always expect
|
# Note: parse_qs returns the values as a list. Since we always expect
|
||||||
# single values, just grab the first from each.
|
# single values, just grab the first from each.
|
||||||
|
|||||||
@ -10,95 +10,6 @@ import pgmon
|
|||||||
# Silence most logging output
|
# Silence most logging output
|
||||||
logging.disable(logging.CRITICAL)
|
logging.disable(logging.CRITICAL)
|
||||||
|
|
||||||
versions_rss = """
|
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PostgreSQL latest versions</title><link>https://www.postgresql.org/</link><description>PostgreSQL latest versions</description><atom:link href="https://www.postgresql.org/versions.rss" rel="self"/><language>en-us</language><lastBuildDate>Thu, 08 May 2025 00:00:00 +0000</lastBuildDate><item><title>17.5
|
|
||||||
</title><link>https://www.postgresql.org/docs/17/release-17-5.html</link><description>17.5 is the latest release in the 17 series.
|
|
||||||
|
|
||||||
</description><pubDate>Thu, 08 May 2025 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/17/release-17-5.html</guid></item><item><title>16.9
|
|
||||||
</title><link>https://www.postgresql.org/docs/16/release-16-9.html</link><description>16.9 is the latest release in the 16 series.
|
|
||||||
|
|
||||||
</description><pubDate>Thu, 08 May 2025 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/16/release-16-9.html</guid></item><item><title>15.13
|
|
||||||
</title><link>https://www.postgresql.org/docs/15/release-15-13.html</link><description>15.13 is the latest release in the 15 series.
|
|
||||||
|
|
||||||
</description><pubDate>Thu, 08 May 2025 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/15/release-15-13.html</guid></item><item><title>14.18
|
|
||||||
</title><link>https://www.postgresql.org/docs/14/release-14-18.html</link><description>14.18 is the latest release in the 14 series.
|
|
||||||
|
|
||||||
</description><pubDate>Thu, 08 May 2025 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/14/release-14-18.html</guid></item><item><title>13.21
|
|
||||||
</title><link>https://www.postgresql.org/docs/13/release-13-21.html</link><description>13.21 is the latest release in the 13 series.
|
|
||||||
|
|
||||||
</description><pubDate>Thu, 08 May 2025 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/13/release-13-21.html</guid></item><item><title>12.22
|
|
||||||
</title><link>https://www.postgresql.org/docs/12/release-12-22.html</link><description>12.22 is the latest release in the 12 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 21 Nov 2024 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/12/release-12-22.html</guid></item><item><title>11.22
|
|
||||||
</title><link>https://www.postgresql.org/docs/11/release-11-22.html</link><description>11.22 is the latest release in the 11 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 09 Nov 2023 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/11/release-11-22.html</guid></item><item><title>10.23
|
|
||||||
</title><link>https://www.postgresql.org/docs/10/release-10-23.html</link><description>10.23 is the latest release in the 10 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 10 Nov 2022 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/10/release-10-23.html</guid></item><item><title>9.6.24
|
|
||||||
</title><link>https://www.postgresql.org/docs/9.6/release-9-6-24.html</link><description>9.6.24 is the latest release in the 9.6 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 11 Nov 2021 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/9.6/release-9-6-24.html</guid></item><item><title>9.5.25
|
|
||||||
</title><link>https://www.postgresql.org/docs/9.5/release-9-5-25.html</link><description>9.5.25 is the latest release in the 9.5 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 11 Feb 2021 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/9.5/release-9-5-25.html</guid></item><item><title>9.4.26
|
|
||||||
</title><link>https://www.postgresql.org/docs/9.4/release-9-4-26.html</link><description>9.4.26 is the latest release in the 9.4 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 13 Feb 2020 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/9.4/release-9-4-26.html</guid></item><item><title>9.3.25
|
|
||||||
</title><link>https://www.postgresql.org/docs/9.3/release-9-3-25.html</link><description>9.3.25 is the latest release in the 9.3 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 08 Nov 2018 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/9.3/release-9-3-25.html</guid></item><item><title>9.2.24
|
|
||||||
</title><link>https://www.postgresql.org/docs/9.2/release-9-2-24.html</link><description>9.2.24 is the latest release in the 9.2 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 09 Nov 2017 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/9.2/release-9-2-24.html</guid></item><item><title>9.1.24
|
|
||||||
</title><link>https://www.postgresql.org/docs/9.1/release-9-1-24.html</link><description>9.1.24 is the latest release in the 9.1 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 27 Oct 2016 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/9.1/release-9-1-24.html</guid></item><item><title>9.0.23
|
|
||||||
</title><link>https://www.postgresql.org/docs/9.0/release-9-0-23.html</link><description>9.0.23 is the latest release in the 9.0 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 08 Oct 2015 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/9.0/release-9-0-23.html</guid></item><item><title>8.4.22
|
|
||||||
</title><link>https://www.postgresql.org/docs/8.4/release-8-4-22.html</link><description>8.4.22 is the latest release in the 8.4 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 24 Jul 2014 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/8.4/release-8-4-22.html</guid></item><item><title>8.3.23
|
|
||||||
</title><link>https://www.postgresql.org/docs/8.3/release-8-3-23.html</link><description>8.3.23 is the latest release in the 8.3 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 07 Feb 2013 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/8.3/release-8-3-23.html</guid></item><item><title>8.2.23
|
|
||||||
</title><link>https://www.postgresql.org/docs/8.2/release-8-2-23.html</link><description>8.2.23 is the latest release in the 8.2 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Mon, 05 Dec 2011 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/8.2/release-8-2-23.html</guid></item><item><title>8.1.23
|
|
||||||
</title><link>https://www.postgresql.org/docs/8.1/release.html</link><description>8.1.23 is the latest release in the 8.1 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 16 Dec 2010 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/8.1/release.html</guid></item><item><title>8.0.26
|
|
||||||
</title><link>https://www.postgresql.org/docs/8.0/release.html</link><description>8.0.26 is the latest release in the 8.0 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Mon, 04 Oct 2010 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/8.0/release.html</guid></item><item><title>7.4.30
|
|
||||||
</title><link>https://www.postgresql.org/docs/7.4/release.html</link><description>7.4.30 is the latest release in the 7.4 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Mon, 04 Oct 2010 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/7.4/release.html</guid></item><item><title>7.3.21
|
|
||||||
</title><link>https://www.postgresql.org/docs/7.3/release.html</link><description>7.3.21 is the latest release in the 7.3 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Mon, 07 Jan 2008 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/7.3/release.html</guid></item><item><title>7.2.8
|
|
||||||
</title><link>https://www.postgresql.org/docs/7.2/release.html</link><description>7.2.8 is the latest release in the 7.2 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Mon, 09 May 2005 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/7.2/release.html</guid></item><item><title>7.1.3
|
|
||||||
</title><link>https://www.postgresql.org/docs/7.1/release.html</link><description>7.1.3 is the latest release in the 7.1 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Fri, 17 Aug 2001 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/7.1/release.html</guid></item><item><title>7.0.3
|
|
||||||
</title><link>https://www.postgresql.org/docs/7.0/release.htm</link><description>7.0.3 is the latest release in the 7.0 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Sun, 12 Nov 2000 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/7.0/release.htm</guid></item><item><title>6.5.3
|
|
||||||
</title><link>https://www.postgresql.org/docs/6.5/release.htm</link><description>6.5.3 is the latest release in the 6.5 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Thu, 04 Nov 1999 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/6.5/release.htm</guid></item><item><title>6.4.2
|
|
||||||
</title><link>https://www.postgresql.org/docs/6.4/release.htm</link><description>6.4.2 is the latest release in the 6.4 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Sun, 03 Jan 1999 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/6.4/release.htm</guid></item><item><title>6.3.2
|
|
||||||
</title><link>https://www.postgresql.org/docs/6.3/c2701.htm</link><description>6.3.2 is the latest release in the 6.3 series.
|
|
||||||
This version is unsupported!
|
|
||||||
</description><pubDate>Mon, 23 Feb 1998 00:00:00 +0000</pubDate><guid>https://www.postgresql.org/docs/6.3/c2701.htm</guid></item></channel></rss>
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class TestPgmonMethods(unittest.TestCase):
|
class TestPgmonMethods(unittest.TestCase):
|
||||||
##
|
##
|
||||||
@ -261,16 +172,13 @@ class TestPgmonMethods(unittest.TestCase):
|
|||||||
def test_get_query__versions(self):
|
def test_get_query__versions(self):
|
||||||
metric = {"type": "value", "query": {0: "DEFAULT", 110000: "NEW"}}
|
metric = {"type": "value", "query": {0: "DEFAULT", 110000: "NEW"}}
|
||||||
|
|
||||||
# Test getting the default version of a query with no lower bound and a newer
|
# Test getting the default version of a query with no lower bound and a newer version
|
||||||
# version
|
|
||||||
self.assertEqual(pgmon.get_query(metric, 100000), "DEFAULT")
|
self.assertEqual(pgmon.get_query(metric, 100000), "DEFAULT")
|
||||||
|
|
||||||
# Test getting the newer version of a query with no lower bound and a newer
|
# Test getting the newer version of a query with no lower bound and a newer version for the newer version
|
||||||
# version for the newer version
|
|
||||||
self.assertEqual(pgmon.get_query(metric, 110000), "NEW")
|
self.assertEqual(pgmon.get_query(metric, 110000), "NEW")
|
||||||
|
|
||||||
# Test getting the newer version of a query with no lower bound and a newer
|
# Test getting the newer version of a query with no lower bound and a newer version for an even newer version
|
||||||
# version for an even newer version
|
|
||||||
self.assertEqual(pgmon.get_query(metric, 160000), "NEW")
|
self.assertEqual(pgmon.get_query(metric, 160000), "NEW")
|
||||||
|
|
||||||
# Test getting a version in bwtween two other versions
|
# Test getting a version in bwtween two other versions
|
||||||
@ -364,8 +272,7 @@ metrics:
|
|||||||
def test_read_config__include(self):
|
def test_read_config__include(self):
|
||||||
pgmon.config = {}
|
pgmon.config = {}
|
||||||
|
|
||||||
# Test reading a config that includes other files (absolute and relative paths,
|
# Test reading a config that includes other files (absolute and relative paths, multiple levels)
|
||||||
# multiple levels)
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
with open(f"{tmpdirname}/config.yml", "w") as f:
|
with open(f"{tmpdirname}/config.yml", "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
@ -754,38 +661,3 @@ metrics:
|
|||||||
)
|
)
|
||||||
self.assertEqual(pgmon.config["dbuser"], "postgres")
|
self.assertEqual(pgmon.config["dbuser"], "postgres")
|
||||||
self.assertEqual(pgmon.config["metrics"]["test1"]["query"][0], "TEST1")
|
self.assertEqual(pgmon.config["metrics"]["test1"]["query"][0], "TEST1")
|
||||||
|
|
||||||
def test_version_num_to_release__valid(self):
|
|
||||||
self.assertEqual(pgmon.version_num_to_release(90602), 9.6)
|
|
||||||
self.assertEqual(pgmon.version_num_to_release(130002), 13)
|
|
||||||
|
|
||||||
def test_parse_version_rss__simple(self):
|
|
||||||
pgmon.parse_version_rss(versions_rss, 13)
|
|
||||||
self.assertEqual(pgmon.latest_version, 130021)
|
|
||||||
self.assertTrue(pgmon.release_supported)
|
|
||||||
|
|
||||||
pgmon.parse_version_rss(versions_rss, 9.6)
|
|
||||||
self.assertEqual(pgmon.latest_version, 90624)
|
|
||||||
self.assertFalse(pgmon.release_supported)
|
|
||||||
|
|
||||||
def test_parse_version_rss__missing(self):
|
|
||||||
# Test asking about versions that don't exist
|
|
||||||
self.assertRaises(
|
|
||||||
pgmon.LatestVersionCheckError, pgmon.parse_version_rss, versions_rss, 9.7
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(
|
|
||||||
pgmon.LatestVersionCheckError, pgmon.parse_version_rss, versions_rss, 99
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_get_latest_version(self):
|
|
||||||
# Define a cluster version here so the test doesn't need a database
|
|
||||||
pgmon.cluster_version_next_check = datetime.now() + timedelta(hours=1)
|
|
||||||
pgmon.cluster_version = 90623
|
|
||||||
|
|
||||||
# Set up a default config
|
|
||||||
pgmon.update_deep(pgmon.config, pgmon.default_config)
|
|
||||||
|
|
||||||
# Make sure we can pull the RSS file (we assume the 9.6 series won't be getting
|
|
||||||
# any more updates)
|
|
||||||
self.assertEqual(pgmon.get_latest_version(), 90624)
|
|
||||||
|
|||||||
@ -11,39 +11,6 @@ zabbix_export:
|
|||||||
groups:
|
groups:
|
||||||
- name: 'My Templates'
|
- name: 'My Templates'
|
||||||
items:
|
items:
|
||||||
- uuid: de1fa757395440118026f4c7a7c4ebbe
|
|
||||||
name: 'PostgreSQL latest supported version'
|
|
||||||
type: DEPENDENT
|
|
||||||
key: pgmon.release.latest
|
|
||||||
delay: '0'
|
|
||||||
preprocessing:
|
|
||||||
- type: JSONPATH
|
|
||||||
parameters:
|
|
||||||
- $.latest
|
|
||||||
master_item:
|
|
||||||
key: 'pgmon[latest_version_info]'
|
|
||||||
tags:
|
|
||||||
- tag: Application
|
|
||||||
value: PostgreSQL
|
|
||||||
- uuid: e1a003317bc043908ee0803704a6e1d0
|
|
||||||
name: 'PostgreSQL release support status'
|
|
||||||
type: DEPENDENT
|
|
||||||
key: pgmon.release.supported
|
|
||||||
delay: '0'
|
|
||||||
preprocessing:
|
|
||||||
- type: JSONPATH
|
|
||||||
parameters:
|
|
||||||
- $.supported
|
|
||||||
master_item:
|
|
||||||
key: 'pgmon[latest_version_info]'
|
|
||||||
tags:
|
|
||||||
- tag: Application
|
|
||||||
value: PostgreSQL
|
|
||||||
triggers:
|
|
||||||
- uuid: 88eac74402d64e7cb853e8cb505b1939
|
|
||||||
expression: 'last(/PostgreSQL by pgmon/pgmon.release.supported)<>1'
|
|
||||||
name: 'PostgreSQL major release is lo longer supported'
|
|
||||||
priority: INFO
|
|
||||||
- uuid: 763920af8da84db8a9a2667d9653cb21
|
- uuid: 763920af8da84db8a9a2667d9653cb21
|
||||||
name: 'PostgreSQL Agent Version'
|
name: 'PostgreSQL Agent Version'
|
||||||
type: HTTP_AGENT
|
type: HTTP_AGENT
|
||||||
@ -57,19 +24,6 @@ zabbix_export:
|
|||||||
tags:
|
tags:
|
||||||
- tag: Application
|
- tag: Application
|
||||||
value: PostgreSQL
|
value: PostgreSQL
|
||||||
- uuid: d890e395fbbc4f2bacbd50e7321fcb9f
|
|
||||||
name: 'PostgreSQL latest version info'
|
|
||||||
type: HTTP_AGENT
|
|
||||||
key: 'pgmon[latest_version_info]'
|
|
||||||
delay: 12h
|
|
||||||
history: '0'
|
|
||||||
value_type: TEXT
|
|
||||||
trends: '0'
|
|
||||||
description: 'Information about the latest PostgreSQL version in the current series'
|
|
||||||
url: 'http://localhost:{$AGENT_PORT}/version'
|
|
||||||
tags:
|
|
||||||
- tag: Application
|
|
||||||
value: PostgreSQL
|
|
||||||
- uuid: 8706eccb7edc4fa394f552fc31f401a9
|
- uuid: 8706eccb7edc4fa394f552fc31f401a9
|
||||||
name: 'Max Frozen XID Age'
|
name: 'Max Frozen XID Age'
|
||||||
type: HTTP_AGENT
|
type: HTTP_AGENT
|
||||||
@ -957,35 +911,6 @@ zabbix_export:
|
|||||||
path: $.repid
|
path: $.repid
|
||||||
- lld_macro: '{#STATE}'
|
- lld_macro: '{#STATE}'
|
||||||
path: $.state
|
path: $.state
|
||||||
- uuid: e22315b0295d4b43aa6b6611ede13e84
|
|
||||||
name: 'Discover Replication Slots'
|
|
||||||
type: HTTP_AGENT
|
|
||||||
key: pgmon_discover_slots
|
|
||||||
delay: 10m
|
|
||||||
item_prototypes:
|
|
||||||
- uuid: a9f53efdce0a4bdc970925f8588e01c5
|
|
||||||
name: 'Replication Slot Stats for {#SLOT_NAME}'
|
|
||||||
type: HTTP_AGENT
|
|
||||||
key: 'pgmon_slot_stats[{#SLOT_NAME}]'
|
|
||||||
history: '0'
|
|
||||||
value_type: TEXT
|
|
||||||
trends: '0'
|
|
||||||
url: 'http://localhost:{$AGENT_PORT}/slot_stats'
|
|
||||||
query_fields:
|
|
||||||
- name: slot
|
|
||||||
value: '{#SLOT_NAME}'
|
|
||||||
url: 'http://localhost:{$AGENT_PORT}/discover_slots'
|
|
||||||
lld_macro_paths:
|
|
||||||
- lld_macro: '{#ACTIVE}'
|
|
||||||
path: $.active
|
|
||||||
- lld_macro: '{#DATABASE}'
|
|
||||||
path: $.database
|
|
||||||
- lld_macro: '{#PLUGIN}'
|
|
||||||
path: $.plugin
|
|
||||||
- lld_macro: '{#SLOT_NAME}'
|
|
||||||
path: $.slot_name
|
|
||||||
- lld_macro: '{#TEMPORARY}'
|
|
||||||
path: $.temporary
|
|
||||||
macros:
|
macros:
|
||||||
- macro: '{$AGENT_PORT}'
|
- macro: '{$AGENT_PORT}'
|
||||||
value: '5400'
|
value: '5400'
|
||||||
@ -1063,22 +988,3 @@ zabbix_export:
|
|||||||
- type: STRING
|
- type: STRING
|
||||||
name: reference
|
name: reference
|
||||||
value: XSCMZ
|
value: XSCMZ
|
||||||
triggers:
|
|
||||||
- uuid: 94ce93c828aa46b4bd4f3732fc7090c6
|
|
||||||
expression: 'last(/PostgreSQL by pgmon/pgmon.release.latest) - last(/PostgreSQL by pgmon/pgmon[version]) >= 1'
|
|
||||||
name: 'PostgreSQL is at least 1 version behind'
|
|
||||||
priority: INFO
|
|
||||||
dependencies:
|
|
||||||
- name: 'PostgreSQL is at least 2 version behind'
|
|
||||||
expression: 'last(/PostgreSQL by pgmon/pgmon.release.latest) - last(/PostgreSQL by pgmon/pgmon[version]) >= 2'
|
|
||||||
- uuid: 2701bcd1223c4ee787f3eca30288e6c6
|
|
||||||
expression: 'last(/PostgreSQL by pgmon/pgmon.release.latest) - last(/PostgreSQL by pgmon/pgmon[version]) >= 2'
|
|
||||||
name: 'PostgreSQL is at least 2 version behind'
|
|
||||||
priority: INFO
|
|
||||||
dependencies:
|
|
||||||
- name: 'PostgreSQL is at least 3 version behind'
|
|
||||||
expression: 'last(/PostgreSQL by pgmon/pgmon.release.latest) - last(/PostgreSQL by pgmon/pgmon[version]) >= 3'
|
|
||||||
- uuid: 3c9adbe8b6f84b3788c6a3e513075df5
|
|
||||||
expression: 'last(/PostgreSQL by pgmon/pgmon.release.latest) - last(/PostgreSQL by pgmon/pgmon[version]) >= 3'
|
|
||||||
name: 'PostgreSQL is at least 3 version behind'
|
|
||||||
priority: INFO
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user