src/CheckMKStaticTag.php
public function batchCreate(array $tags) {
        $requests = [];

        $required = ['title'];

        foreach ($tags as $data) {
            foreach ($required as $attribute) {
                if (!array_key_exists($attribute, $data)) {
                    throw new BadMethodCallException(sprintf(
                        'Missing attribute "%s"',
                        $attribute
                    ));
                }
            }

            $requests[] = [
                'method' => 'checkmk.statictag.create',
                'params' => [
                    'data' => $data
                ]
            ];
        }

        $result = $this->api->batchRequest($requests);

        $tagIDs = [];

        foreach ($result as $tag) {
            // Do not check 'id' because in a batch request it is always NULL:
            if (!array_key_exists('success', $tag) ||
                $tag['success'] !== true) {
                if (array_key_exists('message', $tag)) {
                    throw new RuntimeException(sprintf('Bad result: %s', $tag['message']));
                } else {
                    throw new RuntimeException('Bad result');
                }
            }

            $tagIDs[] = $tag['id'];
        }

        return $tagIDs;
    }
public function batchCreate(array $tags) {
        $requests = [];

        $required = ['title'];

        foreach ($tags as $data) {
            foreach ($required as $attribute) {
                if (!array_key_exists($attribute, $data)) {
                    throw new BadMethodCallException(sprintf(
                        'Missing attribute "%s"',
                        $attribute
                    ));
                }
            }

            $requests[] = [
                'method' => 'checkmk.statictag.create',
                'params' => [
                    'data' => $data
                ]
            ];
        }

        $result = $this->api->batchRequest($requests);

        $tagIDs = [];

        foreach ($result as $tag) {
            // Do not check 'id' because in a batch request it is always NULL:
            if (!array_key_exists('success', $tag) ||
                $tag['success'] !== true) {
                if (array_key_exists('message', $tag)) {
                    throw new RuntimeException(sprintf('Bad result: %s', $tag['message']));
                } else {
                    throw new RuntimeException('Bad result');
                }
            }

            $tagIDs[] = $tag['id'];
        }

        return $tagIDs;
    }
public function batchCreate ( array $ tags ) { $ requests = [ ] ; $ required = [ 'title' ] ; foreach ( $ tags as $ data ) { foreach ( $ required as $ attribute ) { if ( ! array_key_exists ( $ attribute , $ data ) ) { throw new BadMethodCallException ( sprintf ( 'Missing attribute "%s"' , $ attribute ) ) ; } } $ requests [ ] = [ 'method' => 'checkmk.statictag.create' , 'params' => [ 'data' => $ data ] ] ; } $ result = $ this -> api -> batchRequest ( $ requests ) ; $ tagIDs = [ ] ; foreach ( $ result as $ tag ) { // Do not check 'id' because in a batch request it is always NULL: if ( ! array_key_exists ( 'success' , $ tag ) || $ tag [ 'success' ] !== true ) { if ( array_key_exists ( 'message' , $ tag ) ) { throw new RuntimeException ( sprintf ( 'Bad result: %s' , $ tag [ 'message' ] ) ) ; } else { throw new RuntimeException ( 'Bad result' ) ; } } $ tagIDs [ ] = $ tag [ 'id' ] ; } return $ tagIDs ; }
Create one or more static host tags

@param array $tags List of tags;
required attributes per tag: "title";
optional attributes per tag: "tag" (tag ID), "group", "description"

@return array List of identifiers as integers

@throws Exception on error
Create one or more static host tags