Beispiel #1
0
 def _reload_nagios():
     """ Reload the nagios server from within the
         nagios container
     """
     try:
         client = NagiosPlugin._connect()
         # Validate the nagios config is good
         (_stdin, stdout,
          _stderr) = client.exec_command(NagiosPlugin.VERIFY_COMMAND)
         rc = stdout.channel.recv_exit_status()
         output = stdout.read().decode()
         if rc != 0:
             raise exceptions.OpsException(
                 "Validation of the nagios configuration failed:\n"
                 "Command: " + NagiosPlugin.VERIFY_COMMAND + "\n"
                 "Output: " + output + "\n")
         # Reload nagios service
         (_stdin, stdout,
          _stderr) = client.exec_command(NagiosPlugin.RELOAD_COMMAND)
         rc = stdout.channel.recv_exit_status()
         output = stdout.read().decode()
         if rc != 0:
             raise exceptions.OpsException(
                 "service reload of nagios failed:\n"
                 "Command: " + NagiosPlugin.RELOAD_COMMAND + "\n"
                 "Output: " + output + "\n")
     finally:
         client.close()
Beispiel #2
0
 def _connect():
     client = paramiko.SSHClient()
     if os.path.exists(NagiosPlugin.OPSMGR_CONF):
         try:
             parser = configparser.ConfigParser()
             parser.read(NagiosPlugin.OPSMGR_CONF, encoding='utf-8')
             server = parser.get(
                 NagiosPlugin.NAGIOS_SECTION,
                 NagiosPlugin.NAGIOS_SERVER).lstrip('"').rstrip('"')
             userid = parser.get(
                 NagiosPlugin.NAGIOS_SECTION,
                 NagiosPlugin.NAGIOS_USERID).lstrip('"').rstrip('"')
             sshkey = parser.get(
                 NagiosPlugin.NAGIOS_SECTION,
                 NagiosPlugin.NAGIOS_SSHKEY).lstrip('"').rstrip('"')
             prvkey = paramiko.RSAKey.from_private_key_file(sshkey)
             client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
             client.connect(server,
                            username=userid,
                            pkey=prvkey,
                            timeout=30,
                            allow_agent=False)
         except:
             raise exceptions.OpsException(
                 "connection to nagios server failed:\n"
                 "Server: " + server + "\n"
                 "Userid: " + userid + "\n"
                 "Sshkey: " + sshkey + "\n")
     return client
Beispiel #3
0
 def _rm(client, target):
     (_stdin, stdout, _stderr) = client.exec_command('sudo rm -f ' + target)
     rc = stdout.channel.recv_exit_status()
     output = stdout.read().decode()
     if rc != 0:
         raise exceptions.OpsException(
             "Error when removing file or directory:\n"
             "Command: " + 'sudo rm -f ' + target + "\n"
             "Output: " + output + "\n")
Beispiel #4
0
 def _chmod(client, target, perms):
     (_stdin, stdout, _stderr) = client.exec_command('sudo chmod -R ' +
                                                     perms + ' ' + target)
     rc = stdout.channel.recv_exit_status()
     output = stdout.read().decode()
     if rc != 0:
         raise exceptions.OpsException(
             "Error when changing ownership of file or directory:\n"
             "Command: " + 'sudo chmod -R ' + perms + ' ' + target + "\n"
             "Output: " + output + "\n")
Beispiel #5
0
 def _mv(client, src, dst):
     (_stdin, stdout,
      _stderr) = client.exec_command('sudo mv -f ' + src + ' ' + dst)
     rc = stdout.channel.recv_exit_status()
     output = stdout.read().decode()
     if rc != 0:
         raise exceptions.OpsException(
             "Error when moving file or directory:\n"
             "Command: " + 'sudo mv -f ' + src + ' ' + dst + "\n"
             "Output: " + output + "\n")
Beispiel #6
0
 def _mkdir(client, dirname):
     (_stdin, stdout,
      _stderr) = client.exec_command('sudo mkdir -p ' + dirname)
     rc = stdout.channel.recv_exit_status()
     output = stdout.read().decode()
     if rc != 0:
         raise exceptions.OpsException("Error when creating directory:\n"
                                       "Command: " + 'sudo mkdir -p ' +
                                       dirname + "\n"
                                       "Output: " + output + "\n")
Beispiel #7
0
 def _remove_config_files(address):
     try:
         client = GangliaPlugin._connect()
         cmd = ("cat /etc/ganglia/gmetad.conf |grep " + address +
                "; if [ $? == 0 ]; then " + "sudo sed -i 's/" + address +
                "//'  /etc/ganglia/gmetad.conf; service gmetad restart; fi")
         (_stdin, stdout, _stderr) = client.exec_command(cmd)
         rc = stdout.channel.recv_exit_status()
         output = stdout.read().decode()
         if rc != 0:
             raise exceptions.OpsException(
                 "Error when change gmetad config file:\n"
                 "Command: " + cmd + "\n"
                 "Output: " + output + "\n")
     finally:
         client.close()