def validate_mem_gb(value): lc = LocalCommand() mes = lc.get_max_es_memory() if not str(value).isdigit() or int(value) >= mes: raise ValidationError('''Invalid memory! Please use integers less than {}.'''.format(mes))
class Step36Form(forms.Form): lc = LocalCommand() title = '''Setup is now complete! <br /> <br /> Setup log can be found here:<br /> /var/log/nsm/sosetup.log<br /> <br /> Index Node was added. You can run: <br /> curl -XGET 'http://{}:9200/_cluster/health?pretty=true'<br /> to check if node was added to cluster.'''.format(lc.get_ip_mgmt('eth0'))
def save(self, *args, **kwargs): super(NetworkConf, self).save(*args, **kwargs) lc = LocalCommand() data = '''# The loopback network interface auto lo iface lo inet loopback ''' for i in NetworkConf.objects.all(): data += ''' # The {} network interface auto {} iface {} inet static address {} netmask {} network {} broadcast {} gateway {} '''.format(i.interface, i.interface, i.interface, i.address, i.netmask, i.network, i.broadcast, i.gateway) lc.write(data, '/tmp/_interfaces_test')
class Step08Form(forms.Form): lc = LocalCommand() label = 'Memory in GB:' title = '''Please set up memory in GB for index node - on this server you have free ~{}.<br /> Half of this value is deafult'''.format(lc.get_max_es_memory()) q8 = forms.CharField(label=label, max_length=255, min_length=1, required=True, initial='{}'.format(int(lc.get_max_es_memory()) / 2), validators=[validate_mem_gb])
class Step21Form(forms.Form): lc = LocalCommand() label = 'Number of IDS engine processes:' title = '''How many IDS engine processes would you like to run?<br /><br /> This is limited by the number of CPU cores on your system.<br /><br /> If you need to change this setting later, change IDS_LB_PROCS in /etc/nsm/HOSTNAME-INTERFACE/sensor.conf''' q21 = forms.CharField(label=label, max_length=255, min_length=1, required=True, initial=lc.get_cpu_count() / 2, validators=[validate_cpu])
class Step12FormServer(forms.Form): lc = LocalCommand() label = 'Memory in GB:' title = '''Please set up memory in GB for Elastic node - on this server you have free ~{}.<br /> Half of this value is deafult'''.format(lc.get_max_es_memory()) sq12 = forms.CharField(label=label, max_length=255, min_length=1, required=True, #initial='{}'.format(int(100) / 2), validators=[validate_mem_gb]) key = forms.CharField(widget=forms.HiddenInput(attrs={'value':'ES_MEMORY'}))
class Step19Form(forms.Form): lc = LocalCommand() choices = lc.get_if_list() initval = lc.get_if_manual_list() label = 'Network interface(s):' title = '''Which network interface(s) should be monitored?<br /><br /> If you allowed Setup to configure /etc/network/interfaces, your monitor interfaces are already selected.''' q19 = forms.MultipleChoiceField(label=label, required=True, choices=choices, initial=initval, widget=forms.CheckboxSelectMultiple())
class Step24Form(forms.Form): lc = LocalCommand() label = 'Number of Bro processes:' title = '''How many Bro processes would you like to run?<br /><br /> This is limited by the total number of CPU cores on your system,<br /> but you should probably choose no more than HALF your number of CPU cores.<br /><br /> If you need to change this setting later, you can change the lb_procs variable in /opt/bro/etc/node.cfg.''' q24 = forms.CharField(label=label, max_length=255, min_length=1, required=True, initial=lc.get_cpu_count() / 2, validators=[validate_cpu])
class NetworkConf(models.Model): class Meta: verbose_name = 'Interface configuration' verbose_name_plural = 'Interfaces configuration' lc = LocalCommand() if_list = lc.get_if_list() interface = models.CharField(max_length=16, verbose_name='Interface', choices=if_list) address = models.CharField(max_length=128, verbose_name='Address', validators=[validate_ipv4_address]) netmask = models.CharField(max_length=128, verbose_name='Netmask', validators=[validate_ipv4_address]) network = models.CharField(max_length=128, verbose_name='Network', validators=[validate_ipv4_address]) broadcast = models.CharField(max_length=128, verbose_name='Broadcast', validators=[validate_ipv4_address]) gateway = models.CharField(max_length=128, verbose_name='Gateway', validators=[validate_ipv4_address]) def __str__(self): return '{} {}/{}'.format(self.interface, self.address, self.netmask) def save(self, *args, **kwargs): super(NetworkConf, self).save(*args, **kwargs) lc = LocalCommand() data = '''# The loopback network interface auto lo iface lo inet loopback ''' for i in NetworkConf.objects.all(): data += ''' # The {} network interface auto {} iface {} inet static address {} netmask {} network {} broadcast {} gateway {} '''.format(i.interface, i.interface, i.interface, i.address, i.netmask, i.network, i.broadcast, i.gateway) lc.write(data, '/tmp/_interfaces_test')
def validate_cpu(value): lc = LocalCommand() cores = lc.get_cpu_count() if not str(value).isdigit() or int(value) < 1 or int(value) > cores: raise ValidationError('''Please use integers between 1-{}.'''.format(cores))
def validate_int_digit(value): lc = LocalCommand() mes = lc.get_max_es_memory() if not str(value).isdigit() or not int(value): raise ValidationError('''Please use integers only.''')