Trigger count SNMP traps - zabbix

I have SNMP trap sending message to Zabbix each time there's login failure. Message looks like:
20161207.134900 XCB-SNMP-MIB::xcbLoginFailure 0 (null) XCB-SNMP-MIB::description Authentication failed; username='sgsgsgsgsg' XCB-SNMP-MIB::peerAddress 10.138.1.31
I want to for example to get notification when in last 2 minutes I got more than 5 failed logins (so I got more than 5 traps), I tried to do expression like that:
{Testhost:snmptrap["XCB-SNMP-MIB::xcbLoginFailure"].count(2m)}>5
But it isn't working. Is there any mistake in expression, or should I look somewhere else for reason trigger isn't working? If expression is bad, how can I fix it?
Screenshots:

To make it work I changed:
{Testhost:snmptrap["XCB-SNMP-MIB::xcbLoginFailure"].count(2m)}>5
to:
{Testhost:snmptrap["XCB-SNMP-MIB::xcbLoginFailure"].count(2m,username)}>5
since I got 2 types of login failure messages:
20161208.131643 XCB-SNMP-MIB::xcbLoginFailure 0 (null) XCB-SNMP-MIB::description Authentication failed; username='dgdg' XCB-SNMP-MIB::peerAddress 10.138.1.31
and:
20161208.131641 XCB-SNMP-MIB::xcbLoginFailure 0 (null) XCB-SNMP-MIB::description Invalid username; username='' XCB-SNMP-MIB::peerAddress 10.138.1.31
and both of them contain "username", so I just count how many times that phraze occured.

Related

FIWARE- Quantumleap | Error getting Historical Data (422)

I am trying to use echart widget for wirecloud display. The logic of the wiring is:
quantumleapsource -->quantumleap 2 echart --> echart.
I keeping the two errors below:
1. Error getting Historical Data (422): {"description":"The parameter value '1637496000000' for parameter **fromDate** or **toDate** is not valid.","error":"<class 'exceptions.exceptions.InvalidParameterValue'>"}
2. Error creating subscription in the context broker server: Connection Error
I have tried different date formats like: 2021-11-21T12:00:00Z , 2021-11-21T16:00:44.600+00:00 , 2021-11-16T16:00:44.600. But the error persists.
What could be wrong? Or How can use echart in wirecloud?
The issue with the historical data(422) has already been dealt with in https://github.com/Ficodes/quantumleap-source-operator/pull/19
The subscription error is solved by ensuring the context broker and NGSI proxy is up and running. Also key in the correct IP addresses.

How to get last SQL replication error when multithreading is enabled?

Since MySQL 8.0.27, multithreading is now enabled by default for replica servers. Source
Until then, if the replication failed, we could get the exact error from Last_Error in the result of show replica status\G;. Now, the query is replaced by "Anonymous":
Coordinator stopped because there were error(s) in the worker(s). The
most recent failure being: Worker 1 failed executing transaction
'ANONYMOUS' at master log mysql-bin.031116, end_log_pos 81744270. See
error log and/or
performance_schema.replication_applier_status_by_worker table for more
details about this failure or others, if any.
The table performance_schema.replication_applier_status_by_worker does not contain the exact error either:
mysql> select * from performance_schema.replication_applier_status_by_worker\G
*************************** 1. row ***************************
CHANNEL_NAME:
WORKER_ID: 1
THREAD_ID: 128
SERVICE_STATE: ON
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00.000000
LAST_APPLIED_TRANSACTION: ANONYMOUS
LAST_APPLIED_TRANSACTION_ORIGINAL_COMMIT_TIMESTAMP: 2021-11-16 11:35:04.414021
LAST_APPLIED_TRANSACTION_IMMEDIATE_COMMIT_TIMESTAMP: 2021-11-16 11:35:04.414021
LAST_APPLIED_TRANSACTION_START_APPLY_TIMESTAMP: 2021-11-16 11:35:04.416898
LAST_APPLIED_TRANSACTION_END_APPLY_TIMESTAMP: 2021-11-16 11:35:04.420018
APPLYING_TRANSACTION:
APPLYING_TRANSACTION_ORIGINAL_COMMIT_TIMESTAMP: 0000-00-00 00:00:00.000000
APPLYING_TRANSACTION_IMMEDIATE_COMMIT_TIMESTAMP: 0000-00-00 00:00:00.000000
APPLYING_TRANSACTION_START_APPLY_TIMESTAMP: 0000-00-00 00:00:00.000000
LAST_APPLIED_TRANSACTION_RETRIES_COUNT: 0
LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_NUMBER: 0
LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_MESSAGE:
LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_TIMESTAMP: 0000-00-00 00:00:00.000000
APPLYING_TRANSACTION_RETRIES_COUNT: 0
APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_NUMBER: 0
APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_MESSAGE:
APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_TIMESTAMP: 0000-00-00 00:00:00.000000
-- <I've removed 3 other similar blocks>
I can indeed find the error in the MySQL error log (e.g. "Could not execute Write_rows event on table db.table; Duplicate entry '16737' for key 'table.PRIMARY'"), but not from a query anymore.
Is there another query that would give me this last error message? Or a specific setting to log it & display it under show replica status\G;?
Actually, you are correct. Based on the documentation, once you are using MTR (multi-threaded replication), the SQL thread is the coordinator for worker threads. Here’s what the documentation has to say about it:
If the replica is multithreaded, the SQL thread is the coordinator for worker threads. In this case, the Last_SQL_Error field shows exactly what the Last_Error_Message column in the Performance Schema replication_applier_status_by_coordinator table shows. The field value is modified to suggest that there may be more failures in the other worker threads which can be seen in the replication_applier_status_by_worker table that shows each worker thread's status. If that table is not available, the replica error log can be used. The log or the replication_applier_status_by_worker table should also be used to learn more about the failure shown by SHOW SLAVE STATUS or the coordinator table.
In that case, you can check with the performance_schema.replication_applier_status_by_coordinator then know more via performance_schema.replication_applier_status_by_worker . Otherwise, error log can be used.

How to send and receive raw string from MySQL

I am working on a SQL Developer-like application, in which user enters some SQL command and the result from the server is shown in a <div> on web page.
The problem is that user can enter ANY string, valid SQL or not, for example if an user sends select * from employees; I want to receive and display in
the <div> text EXACTLY as below :
+---------+----------+---------------+----------+
| user_id | username | full_name | password |
+---------+----------+---------------+----------+
| 1 | john | John Doe | admin |
And when he enters a bad SQL string, the <div> message should be the standard MySQL error strings , for example :
mysql> select * from usrsss;
ERROR 1146 (42S02): Table 'mydb.usrsss' doesn't exist
I know about security risk , I do not care about it at this point.
Can this be done, as I have no control on the SQL string syntax being sent by user?
First of all, the prompt you see there mysql> represents the MySQL Shell. This is not SQL or JDBC but a command line interface provided by MySQL.
This MySQL Shell allows you to execute:
SQL statements.
A variety of other statements that are NOT part of SQL.
The JDBC API you want to use will allow you to run the first group of statements -- the SQL statements. Unfortunately, it won't allow you to run the second one, so you are out of luck for this one.
Also, for the first group the JDBC API will provide error codes and error messages that are not exactly the same ones you see when using the MySQL Shell.
Bottom line, you can simulate some of these commands, but it will not be the exact same experience that you probably expect.
However... and this is a big one, why do you want to do this in the first place? One of my developers asked me if he could do this, since it's not difficult to implement; this way we could easily run any SQL command from the web page. Great? Well... no. This is a HUGE SECURITY RISK. If anyone hacks your web page, you would be exposing the whole database.
In other words, don't deploy this code to production.
If you are using java.sql.Connection,
create a statement first by using .createStatement().
use .executeQuery() for searching
and .executeUpdate() for inserts, updates and deletes
When searching identify the number of columns to create a table.
ResultSet rs = statement.executeQuery(String sql);
ResultSetMetaData metaData = rs.getMetaData();
In ResultSetMetaData,
.getColumnCount() will give you the column count.
in a for loop create the columns, while creating .getColumnName(int index) will give you the column name.
After creating the table, iterate the ResultSet,
while (rs.next()) {
rs.getString(int columnIndex);
}
use the above method to get values, and add rows to your table.
Don't forget to surround the code block with
try{
} catch(Exception e){
e.getMessage();
}
so if anything goes wrong you can get the SQLException thrown. That will include a message, the probable cause for the error.
Work your way out... Enjoy!

magento enterprise_targetrule/index model not saving

I am executing this code:
$model1 = Mage::getModel('enterprise_targetrule/index')->load(5511);
var_dump($model1);
$model2 = Mage::getModel('enterprise_targetrule/index')->
load(5511)->
setFlag('0')->
save();
var_dump($model2);
$model3 = Mage::getModel('enterprise_targetrule/index')->load(5511);
var_dump($model3);
die();
The outputs from the var_dump calls are exactly what I would expect: $_data[flag] is 1 for $model1, 0 for $model2 and $model3, and $_origData[flag] is 1 for $model1 and $model2, and 0 for $model3.
So far, it is all looking exactly right. However, when I then (immediately after running this code), execute select * from enterprise_targetrule_index on my database, I get this result:
mysql> select * from enterprise_targetrule_index;
+-----------+----------+-------------------+---------+------+
| entity_id | store_id | customer_group_id | type_id | flag |
+-----------+----------+-------------------+---------+------+
| 5511 | 7 | 0 | 1 | 1 |
WHY?
Why is the flag not getting updated? The models are correct, all the fields are correct, the save and load calls all succeed and return perfect results, but the database is not updated! It's like the change I save() doesn't get written, and yet can somehow still be loaded, at least within that script. What is going on here? What is special about this model, that makes it unable to save?
$model2 = Mage::getModel('enterprise_targetrule/index')->load(5511);
$model2->setFlag('0');
$model2->save();
echo $model2->getFlag();
If you use var_dump it displays the whole Object..
Turns out the reason for this, is the die. When sql queries are executed, they are only performed in memory - they don't get written to the database until and unless the process terminates successfully. Because I was using die(), this prevented the queries from being written.
I was thrown by this initially, because it occurs entirely in memory and not in the database. Once it is written, it does go down as a transaction, but the transaction all gets written at the same time, which is why I didn't see the rollback command in the mysql general log - it wasn't technically rolling back, but preventing even the first query from being written. Very strange, and does make testing harder, but good to keep in mind.

Missing Database Table Aro (expected "aros"), create it first

I have an application that uses Cake PHP and it does not want to run properly. I am getting numerous errors and do not even know where to start fixing it:
Notice: Undefined variable: permissions in
app/views/layouts/default.thtml on line 58 Call Stack: 0.0000 637384
{main}() /app/webroot/index.php:0 0.0022 892856
Dispatcher->dispatch() /app/webroot/index.php:84 0.0051 1104112
Controller->_initComponents() /cake/dispatcher.php:227 0.0051 1104616
Component->init() /cake/libs/controller/controller.php:271 0.0051 1105304
Component->__loadComponents() /cake/libs/controller/component.php:59 0.0054 1116768
AclComponent->__construct() /cake/libs/controller/component.php:124 0.0054 1116768
AclComponent->getACL() /cake/libs/controller/components/acl.php:56 0.0074 1543960
Model->__construct() /cake/libs/controller/components/acl.php:72 0.0097 1855456
Model->setSource() /cake/libs/model/model_php5.php:301 0.0103 1856912
Object->cakeError() /cake/libs/model/model_php5.php:518 0.0106 1885784
ErrorHandler->__construct() /cake/libs/object.php:169 0.0111 1892840
At the bottom it says:
Missing Database Table No Database table for model Aro (expected
"aros"), create it first. Notice: If you want to customize this error
message, create app/views/errors/missing_table.html.
Does anyone have an idea what is wrong?
You're missing a database table
It's looking for the table "aros" but can't find it. Create the table based on the ACL part of the CakePHP book.