def setUp(self):

        self._influx_db_name = 'test_db'
        self.i = Influx(database=self._influx_db_name)

        try:
            self.i.create_database(self._influx_db_name)
            #Generate random data  points for 24h
        except:
           self.i.delete_database(self._influx_db_name)
           sleep(1)
           self.i.create_database(self._influx_db_name)
           pass



        self.VRM = VRM_Account.objects.create(vrm_user_id='*****@*****.**',vrm_password="******")

        self.location = Geoposition(52.5,24.3)

        self.site = Sesh_Site.objects.create(site_name=u"Test site",
                                             comission_date=timezone.datetime(2015, 12, 11, 22, 0),
                                             location_city=u"kigali",
                                             location_country=u"rwanda",
                                             vrm_account = self.VRM,
                                             installed_kw=123.0,
                                             position=self.location,
                                             system_voltage=24,
                                             number_of_panels=12,
                                             vrm_site_id=213,
                                             battery_bank_capacity=12321,
                                             has_genset=True,
                                             has_grid=True)


        # Creating permissions for group
        content_type = ContentType.objects.get_for_model(Sesh_Site)
        self.permission = Permission.objects.create(codename='can_manage_sesh_site',
                                                    name='Can add Sesh Site',
                                                    content_type=content_type)

        self.data_point = Data_Point.objects.create(site=self.site,
                                                    soc=10,
                                                    battery_voltage=20,
                                                    time=timezone.now(),
                                                    AC_input=0.0,
                                                    AC_output=15.0,
                                                    AC_Load_in=0.0,
                                                    AC_Load_out=-0.7)
        #create sesh rmc account
        self.test_rmc_account = Sesh_RMC_Account(site=self.site, api_key='lcda5c15ae5cdsac464zx8f49asc16a')
        self.test_rmc_account.save()

        #create rmc status
        self.test_rmc_status = RMC_status.objects.create(site=self.site,
                                                        ip_address='127.0.0.1',
                                                        minutes_last_contact=100,
                                                        signal_strength=27,
                                                        data_sent_24h=12,
                                                        time=datetime.now())
        self.test_rmc_status.save()


        #create influx datapoint
        self.influx_data_point = insert_point(self.site, 'battery_voltage', 10)

        #create test user
        self.test_user = Sesh_User.objects.create_user(username="******",
                                                  email="*****@*****.**",
                                                  password="******",
                                                  phone_number='250786688713',
                                                  on_call=True,
                                                  send_mail=True,
                                                  send_sms=True)



        # Creating test group


        self.test_organisation = Sesh_Organisation.objects.create(name='test_organisation',
                                                                  send_slack=True,
                                                                  slack_token=settings.SLACK_TEST_KEY)

        # Creating test channels
        self.test_channels = Slack_Channel.objects.create(organisation=self.test_organisation,
                                                          name='test_alerts_channel',
                                                          is_alert_channel=True)

        #assign a user to the sites


        assign_perm("view_Sesh_Site",self.test_user,self.site)

        generate_auto_rules(self.site.pk)

        influx_rule = Alert_Rule.objects.create(check_field='battery_voltage',
                                                operator='lt',
                                                site=self.site,
                                                value=20)

        alert.alert_generator()


        self.new_influx_data_point = insert_point(self.site, 'battery_voltage',  24)
        sleep(2) # Added sleep to wait for sometime until the point is written to the db

        # Create data point that will silence alert
        self.new_data_point = Data_Point.objects.create(site=self.site,
                                                    soc=50,
                                                    battery_voltage=24,
                                                    time=timezone.now(),
                                                    AC_input=0.0,
                                                    AC_output=15.0,
                                                    AC_Load_in=0.0,
                                                    AC_Load_out=-0.7)

        self.new_rmc_status = RMC_status.objects.create(site=self.site,
                                                        ip_address='127.0.0.1',
                                                        minutes_last_contact=1,
                                                        signal_strength=27,
                                                        data_sent_24h=12,
                                                        time=datetime.now())


        self.client = Client()
Exemplo n.º 2
0
def alert_engine():
    """
    Periodic task to check rules agains data points
    """
    alert_generator()
    alert_status_check()
Exemplo n.º 3
0
    def setUp(self):

        self._influx_db_name = 'test_db'
        self.i = Influx(database=self._influx_db_name)

        try:
            self.i.create_database(self._influx_db_name)
            #Generate random data  points for 24h
        except:
           self.i.delete_database(self._influx_db_name)
           sleep(1)
           self.i.create_database(self._influx_db_name)
           pass



        self.VRM = VRM_Account.objects.create(vrm_user_id='*****@*****.**',vrm_password="******")

        self.location = Geoposition(52.5,24.3)

        self.site = Sesh_Site.objects.create(site_name=u"Test site",
                                             comission_date=timezone.datetime(2015, 12, 11, 22, 0),
                                             location_city=u"kigali",
                                             location_country=u"rwanda",
                                             vrm_account = self.VRM,
                                             installed_kw=123.0,
                                             position=self.location,
                                             system_voltage=24,
                                             number_of_panels=12,
                                             vrm_site_id=213,
                                             battery_bank_capacity=12321,
                                             has_genset=True,
                                             has_grid=True)


        # Creating permissions for group
        content_type = ContentType.objects.get_for_model(Sesh_Site)
        self.permission = Permission.objects.create(codename='can_manage_sesh_site',
                                                    name='Can add Sesh Site',
                                                    content_type=content_type)

        self.data_point = Data_Point.objects.create(site=self.site,
                                                    soc=10,
                                                    battery_voltage=20,
                                                    time=timezone.now(),
                                                    AC_input=0.0,
                                                    AC_output=15.0,
                                                    AC_Load_in=0.0,
                                                    AC_Load_out=-0.7)
        #create sesh rmc account
        self.test_rmc_account = Sesh_RMC_Account(site=self.site, api_key='lcda5c15ae5cdsac464zx8f49asc16a')
        self.test_rmc_account.save()

        #create rmc status
        self.test_rmc_status = RMC_status.objects.create(site=self.site,
                                                        ip_address='127.0.0.1',
                                                        minutes_last_contact=100,
                                                        signal_strength=27,
                                                        data_sent_24h=12,
                                                        time=datetime.now())
        self.test_rmc_status.save()


        #create influx datapoint
        self.influx_data_point = insert_point(self.site, 'battery_voltage', 10)

        #create test user
        self.test_user = Sesh_User.objects.create_user(username="******",
                                                  email="*****@*****.**",
                                                  password="******",
                                                  phone_number='250786688713',
                                                  on_call=True,
                                                  send_mail=True,
                                                  send_sms=True)



        # Creating test group


        self.test_organisation = Sesh_Organisation.objects.create(name='test_organisation',
                                                                  send_slack=True,
                                                                  slack_token=settings.SLACK_TEST_KEY)

        # Creating test channels
        self.test_channels = Slack_Channel.objects.create(organisation=self.test_organisation,
                                                          name='test_alerts_channel',
                                                          is_alert_channel=True)

        #assign a user to the sites


        assign_perm("view_Sesh_Site",self.test_user,self.site)

        generate_auto_rules(self.site.pk)

        influx_rule = Alert_Rule.objects.create(check_field='battery_voltage',
                                                operator='lt',
                                                site=self.site,
                                                value=20)

        alert.alert_generator()


        self.new_influx_data_point = insert_point(self.site, 'battery_voltage',  24)
        sleep(2) # Added sleep to wait for sometime until the point is written to the db

        # Create data point that will silence alert
        self.new_data_point = Data_Point.objects.create(site=self.site,
                                                    soc=50,
                                                    battery_voltage=24,
                                                    time=timezone.now(),
                                                    AC_input=0.0,
                                                    AC_output=15.0,
                                                    AC_Load_in=0.0,
                                                    AC_Load_out=-0.7)

        self.new_rmc_status = RMC_status.objects.create(site=self.site,
                                                        ip_address='127.0.0.1',
                                                        minutes_last_contact=1,
                                                        signal_strength=27,
                                                        data_sent_24h=12,
                                                        time=datetime.now())


        self.client = Client()
Exemplo n.º 4
0
def alert_engine():
    """
    Periodic task to check rules agains data points
    """
    alert_generator()
    alert_status_check()