Use /rules to create tickscripts
parent
b817c823de
commit
b151e81733
|
@ -19,6 +19,19 @@ export const createRule = (kapacitor, rule) => {
|
|||
})
|
||||
}
|
||||
|
||||
export const createTickScript = async (kapacitor, rule) => {
|
||||
try {
|
||||
return await AJAX({
|
||||
method: 'POST',
|
||||
url: kapacitor.links.rules,
|
||||
data: rule,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const getRules = kapacitor => {
|
||||
return AJAX({
|
||||
method: 'GET',
|
||||
|
@ -65,12 +78,12 @@ export const createTask = async (kapacitor, {id, dbrps, script, type}) => {
|
|||
try {
|
||||
return await AJAX({
|
||||
method: 'POST',
|
||||
url: kapacitor.links.tasks,
|
||||
url: kapacitor.links.rules,
|
||||
data: {
|
||||
id,
|
||||
type,
|
||||
dbrps,
|
||||
script,
|
||||
tickscript: script,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
|
|
|
@ -2,34 +2,19 @@ import React, {PropTypes} from 'react'
|
|||
import SourceIndicator from 'shared/components/SourceIndicator'
|
||||
import TickscriptType from 'src/kapacitor/components/TickscriptType'
|
||||
import MultiSelectDBDropdown from 'shared/components/MultiSelectDBDropdown'
|
||||
import TickscrtiptNewID, {
|
||||
TickscriptEditID,
|
||||
} from 'src/kapacitor/components/TickscriptID'
|
||||
|
||||
const addName = list => list.map(l => ({...l, name: `${l.db}.${l.rp}`}))
|
||||
|
||||
const TickscriptHeader = ({
|
||||
task: {id, type, dbrps},
|
||||
task: {type, dbrps},
|
||||
source: {name},
|
||||
onSave,
|
||||
isEditing,
|
||||
onStopEdit,
|
||||
onStartEdit,
|
||||
onChangeType,
|
||||
onSelectDbrps,
|
||||
isNewTickscript,
|
||||
}) =>
|
||||
<div className="page-header">
|
||||
<div className="page-header__container">
|
||||
<div className="page-header__left">
|
||||
{isNewTickscript
|
||||
? <TickscrtiptNewID
|
||||
isEditing={isEditing}
|
||||
onStopEdit={onStopEdit}
|
||||
onStartEdit={onStartEdit}
|
||||
isNewTickscript={isNewTickscript}
|
||||
/>
|
||||
: <TickscriptEditID id={id} />}
|
||||
</div>
|
||||
<div className="page-header__left" />
|
||||
<div className="page-header__right">
|
||||
<SourceIndicator sourceName={name} />
|
||||
<TickscriptType type={type} onChangeType={onChangeType} />
|
||||
|
@ -60,9 +45,6 @@ TickscriptHeader.propTypes = {
|
|||
}),
|
||||
onChangeType: func.isRequired,
|
||||
isEditing: bool.isRequired,
|
||||
onStartEdit: func.isRequired,
|
||||
onStopEdit: func.isRequired,
|
||||
isNewTickscript: bool.isRequired,
|
||||
}
|
||||
|
||||
export default TickscriptHeader
|
||||
|
|
|
@ -59,17 +59,23 @@ class TickscriptPage extends Component {
|
|||
} = this.props
|
||||
|
||||
let response
|
||||
if (this._isEditing()) {
|
||||
response = await updateTask(kapacitor, task, ruleID)
|
||||
} else {
|
||||
response = await createTask(kapacitor, task)
|
||||
}
|
||||
|
||||
if (response && response.error) {
|
||||
return this.setState({validation: response.error})
|
||||
}
|
||||
try {
|
||||
if (this._isEditing()) {
|
||||
response = await updateTask(kapacitor, task, ruleID)
|
||||
} else {
|
||||
response = await createTask(kapacitor, task)
|
||||
}
|
||||
|
||||
router.push(`/sources/${source.id}/alert-rules`)
|
||||
if (response && response.code === 500) {
|
||||
return this.setState({validation: response.message})
|
||||
}
|
||||
|
||||
router.push(`/sources/${source.id}/alert-rules`)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
handleChangeScript = script => {
|
||||
|
|
Loading…
Reference in New Issue