예제 #1
0
class ConfluenceAPIHelper:
    username = '******'
    password = ''
    base_url = 'https://brianjing.atlassian.net/wiki'

    def __init__(self):
        username = self.username
        password = self.password
        if not self.username:
            username = raw_input('Confluence user name: ')
        if not self.password:
            password = getpass.getpass('Confluence password (hidden): ')
        self.api = ConfluenceAPI(username, password, self.base_url)

    # api.create_new_space({
    #     'key': 'LOL',
    #     'name': 'My testing space',
    #     'description': {
    #         'plain': {'value': 'This is my new testing space', 'representation': 'plain'}
    #     }
    # })

    #Generate a page for our space
    def create_page(self, content):
        print content
        space_key = raw_input('Space key: ')
        page_title = raw_input('Page title: ')
        self.api.create_new_content({
            'type': 'page',
            'title': page_title,
            'space': {
                'key': space_key
            },
            'body': {
                'storage': {
                    'value': content,
                    'representation': 'storage'
                }
            }
        })

    def test_create_page(self):
        #Generate a page for our space
        self.api.create_new_content({
            'type': 'page',
            'title': 'My landing page for TESTSPACE!',
            'space': {
                'key': 'HAC'
            },
            'body': {
                'storage': {
                    'value':
                    '<h1>Welcome to the landing page!</h1><p>Lorem Ipsum</p>',
                    'representation': 'storage'
                }
            }
        })
예제 #2
0
class ConfluenceAPIHelper:
    username = '******'
    password = ''
    base_url = 'https://brianjing.atlassian.net/wiki'

    def __init__(self):
        username = self.username
        password = self.password
        if not self.username:
            username = raw_input('Confluence user name: ')
        if not self.password:
            password = getpass.getpass('Confluence password (hidden): ')
        self.api = ConfluenceAPI(username, password, self.base_url)

    # api.create_new_space({
    #     'key': 'LOL',
    #     'name': 'My testing space',
    #     'description': {
    #         'plain': {'value': 'This is my new testing space', 'representation': 'plain'}
    #     }
    # })

    #Generate a page for our space
    def create_page(self, content):
        print content
        space_key = raw_input('Space key: ')
        page_title = raw_input('Page title: ')
        self.api.create_new_content({
            'type': 'page',
            'title': page_title,
            'space': {'key': space_key},
            'body': {
                'storage': {'value': content,
                            'representation': 'storage'}
            }
        })

    def test_create_page(self):
        #Generate a page for our space
        self.api.create_new_content({
            'type': 'page',
            'title': 'My landing page for TESTSPACE!',
            'space': {'key': 'HAC'},
            'body': {
                'storage': {'value': '<h1>Welcome to the landing page!</h1><p>Lorem Ipsum</p>',
                            'representation': 'storage'
                            }
            }
        })
예제 #3
0
class Chatfluence(BotPlugin):
    """An Err plugin chatfluence"""
    min_err_version = '2.0.0'  # Optional, but recommended
    max_err_version = '3.3.0'  # Optional, but recommended

    def get_configuration_template(self):
        return CONFIG_TEMPLATE

    def activate(self):
        """Triggers on plugin activation"""

        self.log.debug(
            self.config['CONFLUENCE_USERNAME'],
            self.config['CONFLUENCE_PASSWORD'],
            self.config['CONFLUENCE_ENDPOINT']
        )

        self.api = ConfluenceAPI(
            self.config['CONFLUENCE_USERNAME'],
            self.config['CONFLUENCE_PASSWORD'],
            self.config['CONFLUENCE_ENDPOINT']
            )

        super(Chatfluence, self).activate()

    @botcmd()
    def recent(self, mess, args):
        """A command that shows recent blog posts.
        Optionally pass in a result limit."""

        if args:
            limit = args
        else:
            limit = self.config['LIMIT']


        results = self._recent(limit=limit)

        endpoint = self.config['CONFLUENCE_ENDPOINT']

        for result in results:
                posted = self._get_posted_date(result['id'])[:10]

                line = '{0} {1} {2}{3}'.format(
                    posted,
                    result['title'],
                    endpoint.rstrip('/'),
                    result['_links']['tinyui']
                )
                yield line

    def _recent(self, limit=None, space=None):
        """Method to fetch recent blog posts wihtin a space."""

        if not limit:
            limit = self.config['LIMIT']

        if not space:
            space = self.config['CONFLUENCE_KEYSPACE']

        recent = self.api.get_content(
            content_type='blogpost',
            space_key=space,
            limit=limit,
        )

        return recent['results']

    @botcmd()
    def search(self, mess, args):
        """A command that searches confluence.
        This uses the CQL language. https://developer.atlassian.com/confdev/confluence-rest-api/advanced-searching-using-cql
        """

        if '=' not in str(args) and '~' not in str(args):
            cql = 'text ~ "{0}"'.format(args)
        else:
            cql = str(args)

        # remove slack's smart quotes
        cql = cql.replace('“', '"').replace('”', '"')

        self.log.debug('search: {0}'.format(cql))

        results = self._search(cql)

        for result in results:
                posted = self._get_posted_date(result['id'])[:10]

                line = '{0} {1}'.format(
                    posted,
                    result['title'],
                )
                yield line
                self.log.debug(result)


    def _search(self, cql, limit=None):
        """Searches confluence."""

        if not limit:
            limit = self.config['LIMIT']

        results = self.api.search_content(
            cql_str=cql,
            limit=limit
        )
        return results['results']



    def _get_posted_date(self, pageid):
        """Gets date content was created"""

        page = self.api.get_content_by_id(content_id=pageid)
        posted = page['history']['createdDate']

        return posted


    # TODO: can these patterns come from the configuration?
    @re_botcmd(pattern=r"(^| )@news?( |$)", prefixed=False, flags=re.IGNORECASE)
    def listen_for_news(self, msg, match):
        """Mention @news and I will blog it."""

        content = 'Posted by {0}:  \n {1}'.format(msg.frm, msg.body)

        title = ' '.join(msg.body.split()[0:5])
        keyspace = self.config['CONFLUENCE_KEYSPACE']

        result = self._post(title, content, keyspace)

        return result

    def _post(self, title, content, space):
        """Method to make a blog post in a space."""

        try:
            r = self.api.create_new_content({
                'type': 'blogpost',
                'title': title,
                'space': {'key': space},
                'body': {
                    'storage': {'value': content,
                                'representation': 'storage'
                                }
                }
            })
            self.log.debug(r)
            line = 'POSTED: {0} {1} {2}/{3}'.format(
                r['history']['createdDate'][:10],
                r['title'],
                r['_links']['base'],
                r['_links']['tinyui'],
            )

        except Exception as e:
            self.log.critical(e)


        return line
            '[21.11.2016 05:06:08] <20> Error       at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)' \
            '[21.11.2016 05:06:08] <20> Error       at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)' \
            '[21.11.2016 05:06:08] <20> Error       at Veeam.Backup.AgentProvider.CAgentEndpointConnecter.ConnectToAgentEndpoint(ISocket socket, IAgentEndPoint endPoint)]]></ac:plain-text-body></ac:structured-macro></ac:layout-cell></ac:layout-section><ac:layout-section ac:type="single"><ac:layout-cell>' \
            '<h2><span class="mw-headline">Solution</span></h2>' \
            '<p><span class="mw-headline"><span style="color: rgb(37,37,37);">Private fix for v.9.5.0.711 is available.</span></span></p><ac:structured-macro ac:name="panel"><ac:rich-text-body>' \
            '<ol>' \
            '<li><span style="color: rgb(37,37,37);">Make sure, that no jobs are running at the moment;</span></li>' \
            '<li><span style="color: rgb(37,37,37);">Stop all Veeam services;</span></li>' \
            '<li><span style="color: rgb(37,37,37);">Go to installation folder (default: C:\Program Files\Veeam\Backup and Replication\Backup);</span></li>' \
            '<li>Copy the original files somewhere before replacing them<br /><strong>veeam.backup.servicelib.dll</strong><br /><strong>veeam.backup.core.dll</strong><br /><strong>veeam.backup.CloudService.exe</strong></li>' \
            '<li>Copy new DLL files from the fix folder to the installation folder;</li>' \
            '<li>Start Veeam services;</li></ol>' \
            '<p>&nbsp;</p></ac:rich-text-body></ac:structured-macro>' \
            '<p><span class="mw-headline"><br /></span></p></ac:layout-cell></ac:layout-section></ac:layout>'
content ={
    "type": "page",
    "title": "Bug test2",
    "ancestors": [{"type": "page", "id": 13434925}], #http://ee.support2.veeam.local/display/TKB/Found+Bugs
    "space": {
        "key": "TKB"
    },
    "body": {
        "storage": {
            "value": PageBody,
            "representation": "storage"
        }
    }
}

api.create_new_content(content)
예제 #5
0
def confluence(html, metadata):
    # Create API object.
    api = ConfluenceAPI(g_user, g_pass, g_confluence_url)
    update_content = False
    url = ''
    current_history = 0
    update_content_id = ''

    # Check if confluence_id is not null and refer to a valid post
    if metadata['confluence_id'] is not None:
        content = api.get_content_by_id(metadata['confluence_id'])
        if content is not None:
            update_content = True
            current_history = content['version']['number']
            update_content_id = metadata['confluence_id']
            logging.info('updating post with given id')

    # Check if space is available
    if (metadata['confluence_space'] is not None) and (not update_content):
        space = api.get_space_information(metadata['confluence_space'])
        if space is None:
            raise Exception('Space not found')

    # Check if title is unique
    if (metadata['title'] is not None) and (not update_content):
        content = api.get_content(title=metadata['title'])
        if content is not None:
            if content['size'] > 0:
                if g_update_title:
                    update_content = True
                    found_id = content['results'][0]['id']
                    found_post = api.get_content_by_id(found_id)
                    if found_post is not None:
                        current_history = found_post['version']['number']
                        update_content_id = found_id
                    logging.info('Updating duplicate Title')
                else:
                    raise Exception('Title is found but not updating')

    if not update_content:
        post_content = {
            "type": "page",
            "title": metadata['title'],
            "space": {
                "key": metadata['confluence_space']
            },
            "body": {
                "storage": {
                    "value": html,
                    "representation": "storage"
                }
            },
            "ancestors": [{
                "id": metadata['confluence_parent_id']
            }]
        }
        res = api.create_new_content(post_content)
        links = res['_links']
        url = links['base'] + links['webui']
    else:
        post_content = {
            "id": update_content_id,
            "type": "page",
            "title": metadata['title'],
            "space": {
                "key": metadata['confluence_space']
            },
            "version": {
                "number": current_history + 1,
                "minorEdit": False
            },
            "body": {
                "storage": {
                    "value": html,
                    "representation": "storage"
                }
            }
        }
        res = api.update_content_by_id(post_content, update_content_id)
        links = res['_links']
        url = links['base'] + links['webui']
    return url
__author__ = 'Robert Cope'

from PythonConfluenceAPI import ConfluenceAPI

USERNAME = ''
PASSWORD = ''
WIKI_SITE = 'https://my-awesome-organization.atlassian.net/wiki'

api = ConfluenceAPI(USERNAME, PASSWORD, WIKI_SITE)
api.create_new_space({
    'key': 'LOL',
    'name': 'My testing space',
    'description': {
        'plain': {'value': 'This is my new testing space', 'representation': 'plain'}
    }
})
# Generate a page for our space
api.create_new_content({
    'type': 'page',
    'title': 'My landing page for TESTSPACE!',
    'space': {'key': 'LOL'},
    'body': {
        'storage': {'value': '<h1>Welcome to the landing page!</h1><p>Lorem Ipsum</p>',
                    'representation': 'storage'
                    }
    }
})
예제 #7
0
USERNAME = ''
PASSWORD = ''
WIKI_SITE = 'https://my-awesome-organization.atlassian.net/wiki'

api = ConfluenceAPI(USERNAME, PASSWORD, WIKI_SITE)
api.create_new_space({
    'key': 'LOL',
    'name': 'My testing space',
    'description': {
        'plain': {
            'value': 'This is my new testing space',
            'representation': 'plain'
        }
    }
})
# Generate a page for our space
api.create_new_content({
    'type': 'page',
    'title': 'My landing page for TESTSPACE!',
    'space': {
        'key': 'LOL'
    },
    'body': {
        'storage': {
            'value': '<h1>Welcome to the landing page!</h1><p>Lorem Ipsum</p>',
            'representation': 'storage'
        }
    }
})