Andrew Bogott has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/350920 )

Change subject: Monitor wikitech-static mediawiki version
......................................................................


Monitor wikitech-static mediawiki version

This will warn when wikitech-static diverges from the
latest MW version as reported on mediawiki.org.

It will never go critical or page, just warn until
someone upgrades.

Bug: T163721
Change-Id: If7d96b30db26e85ce2779b790520683db554f1ae
---
A modules/icinga/files/check_wikitech_static_version.py
M modules/icinga/manifests/plugins.pp
A modules/icinga/templates/check_commands/check_wikitech_static_version.cfg.erb
M modules/role/manifests/labs/openstack/nova/manager.pp
4 files changed, 115 insertions(+), 0 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  Krinkle: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/modules/icinga/files/check_wikitech_static_version.py 
b/modules/icinga/files/check_wikitech_static_version.py
new file mode 100755
index 0000000..49fd6d5
--- /dev/null
+++ b/modules/icinga/files/check_wikitech_static_version.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Check the MediaWiki version of wikitech-static.wikimedia.org against the
+# latest stable release as reported by mediawiki.org.
+#
+# 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.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+# http://www.gnu.org/copyleft/gpl.html
+
+from __future__ import print_function
+
+import sys
+
+import requests
+
+
+TARGET = 'wikitech-static.wikimedia.org'
+
+OK = 0
+WARNING = 1
+CRITICAL = 2
+UNKNOWN = 3
+
+STATES = {
+    OK: 'OK',
+    WARNING: 'WARNING',
+    CRITICAL: 'CRITICAL',
+    UNKNOWN: 'UNKNOWN',
+}
+
+
+def icinga_exit(state, message, *args, **kwargs):
+    """Print status message and exit."""
+    print('MWVERSION {} - {}'.format(
+        STATES[state],
+        message.format(*args, **kwargs)
+    ))
+    sys.exit(state)
+
+
+def mwapi(server, **kwargs):
+    """Make a MediaWiki Action API call and return the result."""
+    url = 'https://{}/w/api.php'.format(server)
+    query = {'format': 'json', 'formatversion': '2'}
+    query.update(kwargs)
+    req = requests.get(url, params=query)
+    req.raise_for_status()
+    return req.json()
+
+
+# Fetch the latest stable version number from mediawiki.org's
+# [[Template:MW stable release number]] in a format that will match siteinfo
+# output.
+try:
+    stable = mwapi(
+        'www.mediawiki.org',
+        action='expandtemplates', prop='wikitext',
+        text='MediaWiki {{MW stable release number}}',
+    )['expandtemplates']['wikitext']
+except:
+    icinga_exit(
+        UNKNOWN,
+        'Failed to fetch latest MediaWiki version from mediawiki.org')
+
+# Fetch the current version from the target wiki.
+try:
+    version = mwapi(
+        TARGET,
+        action='query', meta='siteinfo', siprop='general',
+    )['query']['general']['generator']
+except:
+    icinga_exit(
+        UNKNOWN, 'Failed to fetch MediaWiki version for {}', TARGET)
+
+if version == stable:
+    icinga_exit(OK, '{} is running {}', TARGET, stable)
+else:
+    icinga_exit(
+        WARNING, '{} is running {}, latest is {}', TARGET, version, stable)
diff --git a/modules/icinga/manifests/plugins.pp 
b/modules/icinga/manifests/plugins.pp
index 05a755b..df6976a 100644
--- a/modules/icinga/manifests/plugins.pp
+++ b/modules/icinga/manifests/plugins.pp
@@ -73,6 +73,12 @@
         group  => 'root',
         mode   => '0755',
     }
+    file { '/usr/lib/nagios/plugins/check_wikitech_static_version':
+        source => 'puppet:///modules/icinga/check_wikitech_static_version.py',
+        owner  => 'root',
+        group  => 'root',
+        mode   => '0755',
+    }
     file { '/usr/lib/nagios/plugins/check_mysql-replication.pl':
         source => 'puppet:///modules/icinga/check_mysql-replication.pl',
         owner  => 'root',
@@ -152,6 +158,14 @@
         group      => 'icinga',
     }
 
+    nagios_common::check_command::config { 'check_wikitech_static_version.cfg':
+        ensure     => present,
+        content    => 
template('icinga/check_commands/check_wikitech_static_version.cfg.erb'),
+        config_dir => '/etc/icinga',
+        owner      => 'icinga',
+        group      => 'icinga',
+    }
+
     # Include check_elasticsearch from elasticsearch module
     include ::elasticsearch::nagios::plugin
 }
diff --git 
a/modules/icinga/templates/check_commands/check_wikitech_static_version.cfg.erb 
b/modules/icinga/templates/check_commands/check_wikitech_static_version.cfg.erb
new file mode 100644
index 0000000..08935f2
--- /dev/null
+++ 
b/modules/icinga/templates/check_commands/check_wikitech_static_version.cfg.erb
@@ -0,0 +1,4 @@
+define command{
+    command_name    check_wikitech_static_version
+    command_line    $USER1$/check_wikitech_static_version
+}
diff --git a/modules/role/manifests/labs/openstack/nova/manager.pp 
b/modules/role/manifests/labs/openstack/nova/manager.pp
index 51657c9..9e757da 100644
--- a/modules/role/manifests/labs/openstack/nova/manager.pp
+++ b/modules/role/manifests/labs/openstack/nova/manager.pp
@@ -64,6 +64,12 @@
         check_command => 'check_wikitech_static',
     }
 
+    # T163721
+    monitoring::service { 'wikitech-static-version':
+        description   => 'Does wikitech-static need a MW version upgrade?',
+        check_command => 'check_wikitech_static_version',
+    }
+
     # For Math extensions file (T126628)
     file { '/srv/math-images':
         ensure => 'directory',

-- 
To view, visit https://gerrit.wikimedia.org/r/350920
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If7d96b30db26e85ce2779b790520683db554f1ae
Gerrit-PatchSet: 7
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Andrew Bogott <[email protected]>
Gerrit-Reviewer: Andrew Bogott <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to