Skip to content

Commit

Permalink
Stored procedure query identification (initial poc)
Browse files Browse the repository at this point in the history
Co-authored-by: Ishika Dawda <[email protected]>
  • Loading branch information
monu-k2io and IshikaDawda committed Nov 6, 2023
1 parent b68e000 commit 1f70368
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ private AbstractOperation preprocessSecurityHook (String sql, String methodName)
SQLOperation sqlOperation = new SQLOperation(this.getClass().getName(), methodName);
sqlOperation.setQuery(sql);
sqlOperation.setParams(this.params);
// for now only those db servers are supported that uses `call`
if (sql.toLowerCase().startsWith("call") || sql.toLowerCase().startsWith("{call")) {
sqlOperation.setStoredProcedureCall(true);
}
sqlOperation.setDbName(NewRelicSecurity.getAgent().getSecurityMetaData().getCustomAttribute(JDBCVendor.META_CONST_JDBC_VENDOR, String.class));
sqlOperation.setPreparedCall(true);
NewRelicSecurity.getAgent().registerOperation(sqlOperation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Dispatcher implements Callable {
private Map<String, Object> extraInfo = new HashMap<String, Object>();
private boolean isNRCode = false;
private static AtomicBoolean firstEventSent = new AtomicBoolean(false);
private final String SQL_STORED_PROCEDURE ="SQL_STORED_PROCEDURE";

public ExitEventBean getExitEventBean() {
return exitEventBean;
Expand Down Expand Up @@ -438,7 +439,12 @@ private JavaAgentEventBean prepareSQLDbCommandEvent(SQLOperation operation,
}
params.add(query);
eventBean.setParameters(params);
eventBean.setEventCategory(operation.getDbName());
if (operation.isStoredProcedureCall()) {
eventBean.setEventCategory(SQL_STORED_PROCEDURE);
} else {
eventBean.setEventCategory(operation.getDbName());
}

return eventBean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SQLOperation extends AbstractOperation {
private String dbName = "UNKNOWN";

private boolean isPreparedCall;
private boolean isStoredProcedureCall;

public SQLOperation(String className, String methodName) {
super(className, methodName);
Expand Down Expand Up @@ -91,5 +92,13 @@ public void setDbName(String dbName) {
this.dbName = dbName;
}
}

public boolean isStoredProcedureCall() {
return isStoredProcedureCall;
}

public void setStoredProcedureCall(boolean storedProcedureCall) {
isStoredProcedureCall = storedProcedureCall;
}
}

0 comments on commit 1f70368

Please sign in to comment.