mg.Logger.Info("create a new folder for alerts that belongs to dashboard because it has custom permissions","org",dash.OrgId,"dashboard_uid",dash.Uid,"folder",folderName)
// create folder and assign the permissions of the dashboard (included default and inherited)
f,err=m.createFolder(dash.OrgId,folderName)
iferr!=nil{
returnMigrationError{
Err:fmt.Errorf("failed to create folder: %w",err),
AlertId:da.Id,
}
}
}
folder=*ptr
permissions,err:=m.getACL(dash.OrgId,dash.Id)
iferr!=nil{
returnMigrationError{
Err:fmt.Errorf("failed to get dashboard %d under organisation %d permissions: %w",dash.Id,dash.OrgId,err),
AlertId:da.Id,
permissions,err:=m.getACL(dash.OrgId,dash.Id)
iferr!=nil{
returnMigrationError{
Err:fmt.Errorf("failed to get dashboard %d under organisation %d permissions: %w",dash.Id,dash.OrgId,err),
AlertId:da.Id,
}
}
err=m.setACL(f.OrgId,f.Id,permissions)
iferr!=nil{
returnMigrationError{
Err:fmt.Errorf("failed to set folder %d under organisation %d permissions: %w",folder.Id,folder.OrgId,err),
AlertId:da.Id,
}
}
folderCache[folderName]=f
}
err=m.setACL(folder.OrgId,folder.Id,permissions)
folder=f
casedash.FolderId>0:
// get folder if exists
f,err:=m.getFolder(dash,da)
iferr!=nil{
returnMigrationError{
Err:fmt.Errorf("failed to set folder %d under organisation %d permissions: %w",folder.Id,folder.OrgId,err),
Err:err,
AlertId:da.Id,
}
}
casedash.FolderId>0:
// link the new rule to the existing folder
folder=&f
default:
// get or create general folder
ptr,err:=m.getOrCreateGeneralFolder(dash.OrgId)
iferr!=nil{
returnMigrationError{
Err:fmt.Errorf("failed to get or create general folder under organisation %d: %w",dash.OrgId,err),
AlertId:da.Id,
f,ok:=folderCache[GENERAL_FOLDER]
if!ok{
// get or create general folder
f,err=m.getOrCreateGeneralFolder(dash.OrgId)
iferr!=nil{
returnMigrationError{
Err:fmt.Errorf("failed to get or create general folder under organisation %d: %w",dash.OrgId,err),
AlertId:da.Id,
}
}
folderCache[GENERAL_FOLDER]=f
}
// No need to assign default permissions to general folder
// because they are included to the query result if it's a folder with no permissions
migrator.Logger.Debug(fmt.Sprintf("Found %d legacy alerts in the database. Unified alerting enabled is %v",resp.Count,ualertEnabled))
returnnil
}
// getAlertFolderNameFromDashboard generates a folder name for alerts that belong to a dashboard. Formats the string according to DASHBOARD_FOLDER format.
// If the resulting string exceeds the migrations.MaxTitleLength, the dashboard title is stripped to be at the maximum length