Can I dynamically set the condition in an IoT Rule SQL? - aws-iot

in this section of yaml file, I need to update condition in sql statement.
for example, user can reset condition to equal 20 instead of 30.
NotifyTemperatureAlarm:
Type: 'AWS::Serverless::Function'
DependsOn: AlertSNSTopic
Properties:
CodeUri: src/notify_temperature_alarm/
Handler: app.lambda_handler
Runtime: python3.9
Architectures:
- x86_64
Events:
PutImageEvent:
Type: IoTRule
Properties:
Sql: Select * FROM 'device/temperature/alarms' where value > 30
Policies:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: "sns:*"
Resource: "*"
Environment:
Variables:
alert_sns: !Ref AlertSNSTopic

make your condition in parameters section such as
Parameters:
TemperatureThreshold:
Type: Number
Default: '20'
then update NotifyTemperatureAlarm such as
NotifyTemperatureAlarm:
Type: 'AWS::Serverless::Function'
DependsOn: AlertSNSTopic
Properties:
CodeUri: src/notify_temperature_alarm/
Handler: app.lambda_handler
Runtime: python3.9
Architectures:
- x86_64
Events:
PutImageEvent:
Type: IoTRule
Properties:
Sql: !Sub "SELECT * FROM 'device/temperature/alarms' where value > ${TemperatureThreshold}"
Policies:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: "sns:*"
Resource: "*"
Environment:
Variables:
alert_sns: !Ref AlertSNSTopic
to make TemperatureThreshold Adjustable, you can update it from cloudformation such as
client = boto3.client('cloudformation')
response = client.update_stack(
StackName = "your_stack_name",
UsePreviousTemplate = True,
Capabilities = ['CAPABILITY_IAM'],
Parameters=[
{
'ParameterKey': 'TemperatureThreshold',
'ParameterValue': str(new_threshold),
}
]
)

Related

I have issue JSONDecodeError at /profile

JSONDecodeError at /profile
Expecting value: line 1 column 1 (char 0)
Request Method: POST
Request URL: http://127.0.0.1:8000/profile
Django Version: 3.2.6
Exception Type: JSONDecodeError
Exception Value:
Expecting value: line 1 column 1 (char 0)
Exception Location: C:\Users\bismi\AppData\Local\Programs\Python\Python310\lib\json\decoder.py, line 355, in raw_decode
Python Executable: C:\Users\bismi\AppData\Local\Programs\Python\Python310\python.exe
Python Version: 3.10.6
Python Path:
['C:\Users\bismi\OneDrive\Desktop\connectyfi modftn\connectyfi',
'C:\Users\bismi\AppData\Local\Programs\Python\Python310\python310.zip',
'C:\Users\bismi\AppData\Local\Programs\Python\Python310\DLLs',
'C:\Users\bismi\AppData\Local\Programs\Python\Python310\lib',
'C:\Users\bismi\AppData\Local\Programs\Python\Python310',
'C:\Users\bismi\AppData\Local\Programs\Python\Python310\lib\site-packages']

flyaway not puck up the last version

i create a version 13 and 14 and when i run the flayway it take just for v13 i have write the sql statement correct and i add the correct number of version and then when the flayway did not take the v14 i try to run it so this is the rest of details belwo
public class V13__createLessonsThumbnalisTables extends BAmanMigration{
#Override
public List<String> getMigrations() {
return Arrays.asList("create table mst_thumbnails_lessons\n" +
"(\n" +
" id bigserial not null,\n" +
" thumbnail_name varchar(255) not null,\n" +
" creation_date timestamp,\n" +
" updated_date timestamp,\n" +
" is_active boolean default true,\n" +
" is_enabled boolean default true not null,\n" +
" created_by int8,\n" +
" updated_by int8,\n" +
" thumbnail_id int8 constraint fk_thumbnail_id references mst_media,\n" +
" primary key (id)\n" +
");");
}
}
public class V14__uploadThumbnailIntoThumbnailLessonTable extends BAmanMigration{
private final LessonRepository LessonRepository;
public V14__uploadThumbnailIntoThumbnailLessonTable(LessonRepository lessonRepository) {
LessonRepository = lessonRepository;
}
ArrayList<String> migrations = new ArrayList<>();
#Override
public List<String> getMigrations() {
List<LessonsEntity> lessons = LessonRepository.findAll();
for (LessonsEntity lesson : lessons) {
String mediaUrl = lesson.getThumbnail().getMediaUrl();
// extract the file name from the url
String fileName = mediaUrl.substring(mediaUrl.lastIndexOf("/") + 1).toLowerCase();
migrations.add("INSERT INTO mst_thumbnails_lessons (thumbnail_name, creation_date, updated_date, is_active, is_enabled, thumbnail_id)" +
" VALUES ( '"+fileName+"', now(), now(), true, true, (select id from mst_media where media_url LIKE '%" + fileName +"% '))");
}
return migrations;
}
}
but the flayway not puck up the last version 14 just take 13 and when i try to run v14 using this command
flyway migrate -target=14 -X
i get
DEBUG: AWS SDK available: false
DEBUG: Google Cloud Storage available: true
DEBUG: Scanning for filesystem resources at 'sql'
ERROR: Skipping filesystem location: sql (not found)
DEBUG: Loading config file: /home/yazan/flyway-9.8.1/conf/flyway.conf
DEBUG: Unable to load config file: /home/yazan/flyway.conf
DEBUG: Unable to load config file: /home/yazan/IdeaProjects/baman-api/flyway.conf
DEBUG: Using configuration:
DEBUG: flyway.jarDirs -> /home/yazan/flyway-9.8.1/jars
DEBUG: flyway.locations -> filesystem:sql
DEBUG: flyway.password -> *****
DEBUG: flyway.target -> 14
DEBUG: flyway.url -> jdbc:postgresql://localhost:5554/baman
DEBUG: flyway.user -> baman
DEBUG: Multiple databases found that handle url 'jdbc:postgresql://localhost:5554/baman': YugabyteDB, CockroachDB, PostgreSQL
DEBUG: Scanning for classpath resources at 'classpath:db/callback' ...
DEBUG: Determining location urls for classpath:db/callback using ClassLoader java.net.URLClassLoader#4a3e3e8b ...
DEBUG: Unable to resolve location classpath:db/callback.
Database: jdbc:postgresql://localhost:5554/baman (PostgreSQL 14.5)
DEBUG: Driver : PostgreSQL JDBC Driver 42.4.1
DEBUG: DDL Transactions Supported: true
DEBUG: Schemas:
DEBUG: Default schema: null
DEBUG: Scanning for SQL callbacks ...
DEBUG: Validating migrations ...
DEBUG: Rolling back transaction...
DEBUG: Transaction rolled back
DEBUG: Memory usage: 42 of 250M
ERROR: Unexpected error
org.flywaydb.core.api.FlywayException: No migration with a target version 14 could be found. Ensure target is specified correctly and the migration exists.
at org.flywaydb.core.internal.info.MigrationInfoServiceImpl.validateTarget(MigrationInfoServiceImpl.java:251)
at org.flywaydb.core.internal.info.MigrationInfoServiceImpl.refresh(MigrationInfoServiceImpl.java:120)
at org.flywaydb.core.internal.command.DbValidate.lambda$validate$0(DbValidate.java:108)
at org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate.execute(TransactionalExecutionTemplate.java:55)
at org.flywaydb.core.internal.command.DbValidate.validate(DbValidate.java:101)
at org.flywaydb.core.Flyway.doValidate(Flyway.java:358)
at org.flywaydb.core.Flyway.lambda$migrate$0(Flyway.java:132)
at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:204)
at org.flywaydb.core.Flyway.migrate(Flyway.java:128)
at org.flywaydb.commandline.Main.executeOperation(Main.java:275)
at org.flywaydb.commandline.Main.main(Main.java:179)

How to extract counterid from below JSON data only if counter_name is matched and add the counterid to another file in shell script

I am writing in shellscript.
I have a JSON data. I need to extract the counterid and pass that data to a .yml file. I want to replace data in the yml file if counter_name (in the JSON data) is matched with the data in the yml file and replace with it counterid.
Example:
{"counterId" : 200001 ,"counterName" = status-total_access"}
Original yml file:
- rename:
fields:
- from: "apache.status.total_kbytes"
to: "apache.status-total_kbytes"
yml file should be changed as:
- rename:
fields:
- from: "apache.status.total_kbytes"
to: "apache.2000001"
So, is there any way to do it in shellscript?
I know there is an option called sed, but don't know how to extract the JSON values.
This is my json data:
[{"counterId":200001,"counterName":"status-total_accesses"},{"counterId":200002,"counterName":"status-total_kbytes"},{"counterId":200003,"counterName":"status-requests_per_sec"},{"counterId":200004,"counterName":"status-bytes_per_sec"},{"counterId":200005,"counterName":"status-bytes_per_request"},{"counterId":200006,"counterName":"workers-busy"}]
This is my yml file:
- rename:
fields:
- from: "apache.status.workers.busy"
to: "apache.workers-busy"
ignore_missing: true
- rename:
fields:
- from: "apache.status.workers.idle"
to: "apache.workers-idle"
ignore_missing: true
- rename:
fields:
- from: "apache.status.total_accesses"
to: "apache.status-total_accesses"
ignore_missing: true
- rename:
fields:
- from: "apache.status.total_kbytes"
to: "apache.status-total_kbytes"
ignore_missing: true
- rename:
fields:
- from: "apache.status.uptime.server_uptime"
to: "apache.uptime-server_uptime"
ignore_missing: true
You will need something like jq. Using jq you will get the counterId and counterName value from each object. In order to achieve this first to iterate over each value, and from it you use again the jq to extract each field. After that, you just sed the name with the value in the original file or a copy.
A very quick implementation billow, this will print each time is doing a sed in the file on the standard output the whole file. You should use -i to replace values in place. json.in and yaml.in are the input files having the content you provided.
#!/bin/bash
for row in $(cat json.in | jq -c '.[]' ); do
value=$(echo ${row}|jq '.counterId' )
name=$(echo ${row}|jq -r '.counterName' )
echo "$value $name"
sed -i "s/$name/$value/g" yaml.in
done
the output was:
- rename:
fields:
- from: "apache.status.workers.busy"
to: "apache.200006"
ignore_missing: true
- rename:
fields:
- from: "apache.status.workers.idle"
to: "apache.workers-idle"
ignore_missing: true
- rename:
fields:
- from: "apache.status.total_accesses"
to: "apache.200001"
ignore_missing: true
- rename:
fields:
- from: "apache.status.total_kbytes"
to: "apache.200002"
ignore_missing: true
- rename:
fields:
- from: "apache.status.uptime.server_uptime"
to: "apache.uptime-server_uptime"
ignore_missing: true

read values as string of yaml with libyaml

I'm need simple example for using libyaml to get all keys+values as strings from yaml file.
lets say i have this yaml file:
Active Groups:
btcoex: yes
datapath: no
Header:
TLV_data_version: 1
command id: 0xf1
group id: 0x01
btcoex:
enabel ATS:
Active: yes
Apply_point: APPLY_POINT_AFTER_ALIVE
selection:
set: 1
table: 3
cpu: 1
how can I just print all the keys and values?

Jasmine-spec-reporter: How to disable "Expected" description of a failed spec

Is it possible to configure the "jasmine-spec-reporter" to NOT display the Expected description of a failed spec.
For instance, in the output below, do not print the last row "Expected true to equal false." :
√ [ 1 ] May NOT enter the system when mandatory fields are empty
× [ 2 ] There is NO "Null Pointer Exception"
- Expected true to equal false.
With 3.1.0 version, you could use spec.displayErrorMessages and summary.displayErrorMessages options:
new SpecReporter({
spec: {
displayErrorMessages: false
},
summary: {
displayErrorMessages: false
}
})

Resources