def main(): global plugin plugin = Plugin(must_threshold=False) plugin.add_arg("l", "logical-volume", "Comma seperated list of VG/LV, eg vg00/data,vg00/snap", required=False) plugin.add_arg("V", "volume-group", "Comma seperated list of VG, eg vg00,vg01", required=False) plugin.add_arg("a", "check-all", "Check all LVs", required=False, action="store_true") plugin.activate() lvs = plugin["logical-volume"] and plugin["logical-volume"].split( ",") or [] vgs = plugin["volume-group"] and plugin["volume-group"].split(",") or [] if not lvs and not vgs and not plugin['check-all']: plugin.parser.error( "Either logical-volume or volume-group must be specified") elif plugin['check-all'] and (lvs or vgs): plugin.parser.error( "Mixing check-all and logical-volume or volume-group does not make sense" ) check_mirror(lvs, vgs, plugin['check-all'], plugin['host']) (code, message) = (plugin.check_messages(joinallstr="\n")) plugin.nagios_exit(code, message)
def setUp(self): self.argv_store = sys.argv from pynag.Plugins import simple as Plugin self.np = Plugin(must_threshold=False) sys.stdout = StringIO()
def test_shortname(self): from pynag.Plugins import simple as Plugin np = Plugin(shortname='testcase') self.assertEqual(np.data['shortname'], 'testcase')
def setUp(self): self.argv_store = sys.argv from pynag.Plugins import simple as Plugin self.np = Plugin() sys.stdout = StringIO() sys.stderr = StringIO()
#! /usr/bin/python from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin import boto ## Create the plugin option np = Plugin() ## Add a command line argument np.add_arg("n", "name", "Amazon ELB name", required=True) np.add_arg("i", "instance", "Amazon EC2 instance ID", required=True) ## This starts the actual plugin activation np.activate() ## Use specified ELB name elb_name = np['name'] instance_id = np['instance'] ## Unable to connect try: conn = boto.connect_elb() except boto.exception.NoAuthHandlerFound: np.nagios_exit( UNKNOWN, "Unable to log into AWS. Please Check your /etc/boto.cfg file or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variable." ) ## Unable to get elbs try: instances_health = conn.describe_instance_health(elb_name)
#!/usr/bin/python import os.path import sys pynagbase = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) sys.path[0] = pynagbase # Standard init import pynag.Plugins from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin np = Plugin(must_threshold=False) # Feed fake data for range checking np.add_arg('F', 'fakedata', 'fake data to test thresholds', required=True) # Activate np.activate() # Test supplied fake data against thresholds np.check_range(int(np['fakedata']))
def main(): global np global tmpdir # new pynag.Plugin np = Plugin(must_threshold=False) # Arguments np.add_arg('f', 'file', 'Remote file, space seperate multiple files', required=False) np.add_arg('w', 'warning', 'Warn if tftp downloads take longer', required=False) np.add_arg('c', 'critical', 'Critical if tftp downloads take longer', required=False) np.add_arg('l', 'longoutput', 'Each file broken up into a new line for readability', required=False, action="store_true") # Activate np.activate() if np['host'] == "": np.nagios_exit(UNKNOWN, "Hostname is required") tmpdir = mktmpdir() end_time = time.time() + int(np['timeout'] or 20) # data.txt add manually contient list of file that we will check # dirname = os.path.join('data', 'tftplist.txt') dir = os.path.dirname(os.path.realpath(__file__)) with open(dir + '/data.txt', 'r') as myfile: files = myfile.read().replace('\n', '') # creat list of ips #files = np['file'].split() with open(dir + '/ips.txt', 'r') as myips: ips = myips.read().replace('\n', '') # Loop through the files for ip in ips: for file in files: file_start_time = time.time() try: size = tftp_get(ip, file, timeout=(end_time - time.time())) file_end_time = time.time() run_time = time.time() - file_start_time if size is not False: if np['critical'] and run_time >= int(np['critical']): stat = CRITICAL elif np['warning'] and run_time >= int(np['warning']): stat = WARNING else: stat = OK np.add_message( stat, "tftp://%s/%s got %iB in %.2f secs" % (np['host'], file, size, (file_end_time - file_start_time))) np.add_perfdata("%s_size" % (file), size) np.add_perfdata("%s_fetch" % (file), (file_end_time - file_start_time)) except Exception, e: np.nagios_exit(UNKNOWN, e)
def setUp(self): self.argv_store = sys.argv from pynag.Plugins import simple as Plugin self.np = Plugin()
# This software 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, # see <http://www.gnu.org/licenses/>. import re import subprocess from pynag import Plugins from pynag.Plugins import simple as Plugin DEFAULT_CHRONYD_PORT = 323 plugin = Plugin() # Specify arguments to the plugin plugin.add_arg('p', 'port', 'Chrony UDP port', required=None) plugin.activate() if plugin['critical'] <= plugin['warning']: plugin.parser.error( 'Critical level cannot be lesser than or equal to warning') if plugin['host'] is None: plugin['host'] = 'localhost' if plugin['port'] is None: plugin['port'] = DEFAULT_CHRONYD_PORT