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); }
public void ActivateLLDPAgent() { try { _bash.Install("lldpd"); } catch (Exception) { // ignored } try { _bash.Execute("lldpd -d"); } catch (ProcessException processException) { if (processException.ExitCode != 1) { throw; } } }
public LLDPServices(IBashCommand bash) { this._bash = bash; _bash.Install("lldpd"); }