Esempio n. 1
0
        public async Task <string> Handle(SNMPConfiguration configuration)
        {
            var settings = await settingsRepository.GetSettings();

            settings.SNMPConfiguration = configuration;


            bash.Install("snmpd");
            bash.Install("snmp");
            bash.Install("libsnmp-dev");

            var snmpd = await File.ReadAllTextAsync(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "snmpd.conf"));

            snmpd = snmpd.FormatWith(configuration);

            var snmpdPath = "/etc/snmp/snmpd.conf";

            bash.Execute("/etc/init.d/snmpd stop");

            if (File.Exists(snmpdPath))
            {
                File.Copy(snmpdPath, $"/etc/snmp/snmpd_{DateTime.Now.Ticks}.bak");
            }

            using StreamWriter stream = File.CreateText(snmpdPath);
            await stream.WriteAsync(snmpd);

            bash.Execute("/etc/init.d/snmpd start");

            await settingsRepository.SaveSettings(settings);

            return(null);
        }
Esempio n. 2
0
    public void ActivateLLDPAgent()
    {
        try
        {
            _bash.Install("lldpd");
        }
        catch (Exception)
        {
            // ignored
        }

        try
        {
            _bash.Execute("lldpd -d");
        }
        catch (ProcessException processException)
        {
            if (processException.ExitCode != 1)
            {
                throw;
            }
        }
    }
Esempio n. 3
0
    public LLDPServices(IBashCommand bash)
    {
        this._bash = bash;

        _bash.Install("lldpd");
    }